Karl Morrison Karl Morrison - 27 days ago 7
Node.js Question

Accessing arguments sent via npm run-script

I run the command:

npm run a_script --oki="odo"


How do I get the value of
oki
in my script? I'd like to use it for example:
if(process.argv.oki === 'odo')
.

I tried:

console.log(process.argv);


It doesn't show up there.

I read https://docs.npmjs.com/cli/run-script and it doesn't give an example.

Answer

You just have to insert two dashes between the script name and the argument list for npm to pass them to your script.

e.g. npm run a_script -- --oki="odo"