You could also do that:
In package.json
:
"scripts": {
"cool": "./cool.js"
}
In cool.js
:
console.log({ myVar: process.env.npm_config_myVar });
In CLI:
npm --myVar=something run-script cool
Should output:
{ myVar: 'something' }
Update: Using npm 3.10.3, it appears that it lowercases the process.env.npm_config_
variables? I'm also using better-npm-run
, so I'm not sure if this is vanilla default behavior or not, but this answer is working. Instead of process.env.npm_config_myVar
, try process.env.npm_config_myvar