I have a secret key called API_KEY
that I want to access inside of package.json
's scripts
.
package.json
{
"scripts": {
"start": "web-ext run --api-key=API_KEY"
}
}
My .env
file contains API_KEY
:
API_KEY=abc123
How can I access the value of API_KEY
inside package.json
's scripts
while still keeping it a secret because I need to push package.json
publicly?
Currently, I do the following which works but not cross-platform:
package.json
{
"scripts": {
"start": "web-ext run --api-key=$API_KEY"
}
}
And when running start
script I do it like:
API_KEY=abc123 npm start
This works thanks to Bash Programming Language but it doesn't work on Windows. I need to replace $API_KEY
in start
script with %API_KEY%
. But I want it to be cross-platform. Is there any other way?