Home > Software engineering >  Set environment variables in package.json
Set environment variables in package.json

Time:12-06

I've had a look at quite a number of answers to questions similar to mine but i've not been able to find a working solution for my use case yet.

I've got an environment variable of lets say auth=false. i'd like to set auth=true when i run a particular script in my package.json.

Script in package.json looks like this:

 "dev-use-auth": "auth=true && npm run dev"

After running this script, process.env.auth is still set to false. I've also tried using the cross-env package with no luck

CodePudding user response:

This, most likely, would depend on the OS, but for Linux environments you should get rid of the &&.

The && indicates that you wish to run the commands serially.

Try this, instead:

 "dev-use-auth": "auth=true npm run dev"

CodePudding user response:

it depends on the operative system you are working on, cross-env will help you running on multiple operative systems by calling it:

 "dev-use-auth": "cross-env auth=true npm run dev"

on windows:

 "dev-use-auth": "set auth=true && npm run dev"

on unix (mac, linux, etc..c)

 "dev-use-auth": "auth=true npm run dev"

CodePudding user response:

This, most likely, would depend on the OS, but for Linux environments you should get rid of the &&.

The && indicates that you wish to run the commands serially.

Try this, instead:

"dev-use-auth": "auth=true npm run dev"

  • Related