2

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.

Audwin Oyong
  • 2,247
  • 3
  • 15
  • 32
Selvam Raju
  • 196
  • 4
  • 14

2 Answers2

5

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"
Mike Cluck
  • 31,869
  • 13
  • 80
  • 91
2

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.

Arpan Kc
  • 928
  • 1
  • 6
  • 19