Hello guys, by following NestJS docs and TypeOrm docs i was able to connect my project with a Database, generate the data source file and make everything work as expected in development mode (npm run start:dev).
My question now is, how could i make it so it properly works for both dev and prod environments? i have questions such as...
- Why does .dist folder after
npm run buildincludes .ts files - Should i have my migrations in/outside src folder.
- Should my data-source.ts file (code below) define different directory names based on the NODE_ENV var?
// data-source.ts
import 'reflect-metadata';
import 'dotenv/config';
import { DataSource } from 'typeorm';
import { join } from 'path';
///////////////////////////////////////////////////////
// ONLY USED FOR TYPEORM MIGRATIONS
///////////////////////////////////////////////////////
export const AppDataSource = new DataSource({
type: 'postgres',
host: process.env.DB_HOST,
port: Number(process.env.DB_PORT),
username: process.env.DB_USER,
password: process.env.DB_PASSWORD,
database: process.env.DB_NAME,
entities: [join(__dirname, '**', 'entities', '*.entity.{ts,js}')],
migrations: [join(__dirname, '**', 'migrations', '*.{ts,js}')],
synchronize: false,
migrationsRun: false,
migrationsTableName: 'migrations',
migrationsTransactionMode: 'all',
});
I Tried to find examples of this, but haven't found it yet. Thanks!