nest start command should have option to accept -r flag same as like node -r. For config management I'm using .env file and during development I want to load environment variables from this .env file. On production server these environment variables should already be present. I'm using dotenv for this. I installed dotenv as dev dependency and want to use it via -r flag. In earlier versions of nest I was using dotenv like
"start:local": "ts-node -r tsconfig-paths/register -r dotenv/config src/main.ts"
In latest version start:dev is defined via nest package. like
"start:dev": "nest start --watch",
This does not allow me to add -r flag in command.
nest start should have a flag --r to require package via command. Something like npm start --r dotenv/config.
Align npm start command with node usage.
Please, install the latest version of NestJS CLI. Once it's installed, try this:
nest start --watch -e "node -r dotenv/config"
Alternatively, you can use --exec instead of -e
I tried to add .env path, but it is not wokring.
"nest start -e 'node -r dotenv/config dotenv_config_path=env/.env.development'"
Normal command with node
"node -r dotenv/config your_script.js dotenv_config_path=/custom/path/to/your/env/vars"
Most helpful comment
Please, install the latest version of NestJS CLI. Once it's installed, try this:
Alternatively, you can use
--execinstead of-e