Nest-cli: add -r (node --require) flag in nest start command

Created on 29 Nov 2019  路  2Comments  路  Source: nestjs/nest-cli

Feature Request

Is your feature request related to a problem? Please describe.

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.

Describe the solution you'd like

nest start should have a flag --r to require package via command. Something like npm start --r dotenv/config.

What is the motivation / use case for changing the behavior?

Align npm start command with node usage.

Most helpful comment

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

All 2 comments

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"

Was this page helpful?
0 / 5 - 0 ratings