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.

4
  • I have the same issue with windows. Still could not find a solution for the. Hope this might help you stackoverflow.com/questions/39529870/… Commented Aug 21, 2018 at 9: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: stackoverflow.com/questions/9249830/… Commented Aug 21, 2018 at 10:11
  • Great..... you could answer your own question and that will help others too :) Commented Aug 21, 2018 at 10:13
  • You can read this answer stackoverflow.com/a/57509175/11127383 Commented Aug 15, 2019 at 12:59

1 Answer 1

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?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.