The problem
Ideally, I need to use a variable passed via terminal in some npm scripts.
For example, with the command set TOKEN=blabla&& npm run staging
, where the scripts look like the following:
"staging": "run-s build:steps:* && run-s langcheck",
"build:steps:env": "npx dotenv-vault pull .env --dotenvMe=$TOKEN",
I want the $TOKEN to be replaced by the value passed in the terminal.
However, this did not work. And trying to troubleshoot, I ended up with a very minimal reproduction that I documented below.
Minimal Reproduction
Need to pass an environment variable to npm script inside package.json.
...
"scripts": {
"check": "echo $SECRET",
}
...
Using the following command on Windows
set SECRET=hello&& npm run check
Actual Output vs Expected Output
The output shows $SECRET instead of the "hello" that is intended
> echo $SECRET
$SECRET
How can I "receive" the passed variable inside the npm script?
What I tried
I have tried following this answer from another StackOverflow question, but does not seem to work in my case.