javascript - Setting NODE_ENV differs between Mac and Windows - Stack Overflow

I work with a team of 4 and I'm the only Mac user and my peers are using Windows machine.My team

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 mit my code in repository they will be affected.

Is there any mon solution which can be used to get rid of this platform issue?

Thanks in advance.

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 mit my code in repository they will be affected.

Is there any mon solution which can be used to get rid of this platform issue?

Thanks in advance.

Share Improve this question edited Oct 3, 2021 at 23:01 Audwin Oyong 2,5213 gold badges19 silver badges36 bronze badges asked Jul 2, 2018 at 14:33 Selvam RajuSelvam Raju 3056 silver badges15 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 6

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.

One solution can to create a "start-mac" :"export NODE_ENV=prod && node index.js" script only for mac machine. In package.json you can add custom scripts for windows and mac if its not to update the old scripts.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744182174a4562032.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信