1

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.

Faizi
  • 410
  • 1
  • 8
  • 13
  • I have the same issue with windows. Still could not find a solution for the. Hope this might help you https://stackoverflow.com/questions/39529870/ifprocess-env-node-env-production-always-false – It worked yesterday. Aug 21 '18 at 09:52
  • 1
    @MonkeyDLuffy, 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: https://stackoverflow.com/questions/9249830/how-can-i-set-node-env-production-on-windows – Faizi Aug 21 '18 at 10:11
  • Great..... you could answer your own question and that will help others too :) – It worked yesterday. Aug 21 '18 at 10:13
  • You can read this answer https://stackoverflow.com/a/57509175/11127383 – Daniel Danielecki Aug 15 '19 at 12:59

1 Answers1

6

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?

Faizi
  • 410
  • 1
  • 8
  • 13