Home > Software design >  Doing nodemon -r dotenv/config index.js
Doing nodemon -r dotenv/config index.js

Time:02-21

For maximum portability I'm not doing import 'dotenv/config' within my code, but I'm doing

node -r dotenv/config index.js

Now, I'm starting to use nodemon, which says in README,

To use nodemon, replace the word node on the command line when executing your script.

However, when I'm doing nodemon -r dotenv/config index.js, I only get an usage prompt:

  Usage: nodemon [nodemon options] [script.js] [args]

  See "nodemon --help" for more.

Is hard-coding import 'dotenv/config' within my code the only option that I have?

CodePudding user response:

If you use --exec you can specify the exact command you want nodemon to run your script against, which lets you specify -r.

So in your case it would be:

nodemon --exec "node -r dotenv/config" index.js
  • Related