So i am unable to use typ[e orm with nest js so i have used this as config file or data source file
import { DataSourceOptions } from 'typeorm';
import dotenv from 'dotenv';
import path, { join } from 'path';
dotenv.config();
export function getConfig(): DataSourceOptions {
console.log("path.resolve(process.cwd()", join(process.cwd(), 'src/migrations'))
return {
type: 'postgres',
host: process.env.DB_HOST,
port: Number(process.env.DB_PORT),
username: process.env.DB_USERNAME,
password: process.env.DB_PASSWORD,
database: process.env.DB_NAME,
synchronize: process.env.DB_SYNCHRONIZATION === 'true',
migrations: [path.join(process.cwd(), '/src/migrations', '*{.ts,.js}')],
entities: [
path.join(process.cwd(), '/src/**/*.entity.{.ts,.js}')
],
migrationsTableName: 'migrations',
ssl: process.env.NODE_ENV === 'production',
};
}
this is my app.module.ts
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { getConfig} from './config/database.config';
import "reflect-metadata"
@Module({
imports: [
TypeOrmModule.forRoot(getConfig()),
],
controllers: [AppController],
providers: [AppService],
})
export class AppModule{};
the following commands wwork on it when i use the nest migrate run and create and genreate a migration what doesnt work is nest start : dev it is uanble to connect to db however when i use .js format it works normally what has went wrong can u tell