How about colleagues, I have two files .env and .env.development , I am using the typeorm configuration file and I need to extract the variables from .env.development , I have no problem extracting the variables from the .env file but I need it to be specifically from .env.development , I am using the custom-env library to select the .env.development file but it still extracts the default .env file
orm.config.ts
import { ConnectionOptions } from "typeorm";
//si extrae las variables pero del archivo .env y requiero que sea del .env.development
const envfile = process.cwd() + '\\.env.development';
require('custom-env').env('development', `${process.cwd()}`)
console.log(process.env.DB_HOST)
const dbmaster = {
host: process.env.DB_HOST,
port: process.env.DB_PORT,
username: process.env.DB_USERNAME,
password: process.env.DB_PASSWORD,
database: process.env.DB_NAME,
}
const config: ConnectionOptions = {
type: 'mssql',
host: dbmaster.host,
port: Number(dbmaster.port),
username: dbmaster.username,
password: dbmaster.password,
database: dbmaster.database,
entities: ['src/models/**/*.entity{.ts,.js}'],
options: {
enableArithAbort: true
},
synchronize: true,
migrationsRun: true,
logging: true,
migrations: ['src/database/migrations/**/*{.ts,.js}'],
cli: {
migrationsDir: 'src/database/migrations',
}
}
export = config
Any ideas or if you have any other library or method for my goal? I would appreciate it. Regards
At last I was able to load the file .env.development env-cmd the solution is simple and easy add the following in the package.json :
This according to the env-cmd documentation so my orm.config.ts would look like this :