How override nodejs config when it run from npm?

1.2k Views Asked by At

Here is documentation about node config:

node myapp.js --NODE_CONFIG='{"Customer":{"dbConfig":{"host":"customerdb.prod"}}}'

BUt what if I run npm script? In this case all parameters will passed into npm not nodejs, am I wrong? How to pass --NODE_CONFIG from command line?

P.S. set up NODE_CONFIG as environment variable is not a solution in my case.

1

There are 1 best solutions below

0
On

In order to inject args into an inner npm command, you need to use a -- delimiter.

package.json

"scripts": {
  "myscript": "node myapp.js"
}

And run this command to inject the NODE_CONFIG

npm run myscript -- --NODE_CONFIG='{"Customer":{"dbConfig":{"host":"customerdb.prod"}}}'