Can Not Set Environment Variable in NodeJS App-Windows

血红的双手。 提交于 2021-02-19 07:40:31

问题


I am learning NodeJS and I need to know how to set my production environment using process.env.___ .When I run

console.log(app.get('env')); //app is express object

I get output on command prompt development as environment. But if I try to set an environment variable eg. process.env.NODE_ENV, on command prompt I write :set NODE_ENV=productionand then again try : console.log(process.env.NODE_ENV); I get output: undefined. I've been struggling hard and searching online but have't got a solution yet.

Please, guide me in this matter.


回答1:


I just dug a little and found that in poweshell type $env:NODE_ENV="production". It did the work for me. Remember the dollar sign and quotes. Here is the source: How can I set NODE_ENV=production on Windows?



来源:https://stackoverflow.com/questions/51945761/can-not-set-environment-variable-in-nodejs-app-windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!