Member-only story
Connect with SSH Tunneling in NestJS TypeORM
Hello everyone 👋,
I am Himanshu Singh. I am an Engineer and recently after working as a frontend engineer for more than 2 years, I started doing full-stack.
I was recently given a task to replace PostgreSQL with MySQL in a new project. The project was written in NestJS and it was using TypeORM to handle the database.
I had not worked with NestJS before, so I only tried to understand the code that was relevant to get the work done.
As I have mentioned many times in my previous blogs we use SSH tunneling to connect to our DB, so I had to do the same thing to use MySQL with TypeORM.
I didn’t find any blog that explains how that can be done, so I thought to write one myself.
Let’s begin!
You can read my other blogs at https://hsnice16.medium.com/
Connect with SSH Tunneling
The project was using TypeOrmModule
of @nestjs/typeorm
to return the info for a data source. It was using forRootAsync
like below
import { ConfigService } from '@nestjs/config';
import { TypeOrmModule } from '@nestjs/typeorm';
TypeOrmModule.forRootAsync({
…,
useFactory: async (configService: ConfigService) => {
…
},
…
})