I work with a team of 4 and I'm the only Mac user and my peers are using Windows machine. My team members (Windows users) use the following which was not working on my Mac machine:
"start": "set \"NODE_ENV=prod\" && node index.js"
And when I tried to print process.env.NODE_ENV in log it returned undefined.
Then after browsing, I used the following on my Mac and it was working fine:
"start: "export NODE_ENV=prod && node index.js"
Now if I commit my code in repository they will be affected.
Is there any common solution which can be used to get rid of this platform issue?
Thanks in advance.
You can use the cross-env package to set environment variables in a cross-platform way.
To install it:
npm install --save-dev cross-env
To use it:
"start": "cross-env NODE_ENV=prod node index.js"
An alternative solution could be keeping all your environment variables in the respective node environment the code is running in. And for local development, you could add a .env file and use a package like dotenv to populate the environment variables.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With