npm run script not writed in package

42 Views Asked by At

I can not find some doc in my help. In my npm project I have the script start

"start": "cross-env NODE_ENV=development node server"

I must invoke the script start with one or more vars from cli (I can not change the package.json), example:

npm run start OTHER=1000

the "OTHER" is a var how is NODE_ENV, but is it possibile write (I know is it not possibile, I ask you some solution to do it):

npm run cross-env NODE_ENV=development OTHER=1000 node server
1

There are 1 best solutions below

1
On

You can define the environment variable as you run npm. Like this:

OTHER=1000 npm run start

npm picks it up and passes it to the script.

Or you can predefine it. Like this (sh, bash)

export OTHER=1000
npm run start

If you're on a windows cmd shell, try this

set OTHER=1000
npm run start