I'm using windows 7. I try to use SET NODE_ENV="development"
command from cmd but this won't help. Also in npm in scripts I use NODE_ENV=development
node app.js. But env still undefined.
Asked
Active
Viewed 1,177 times
1

Jordan.J.D
- 7,999
- 11
- 48
- 78

Oleg Baranovsky
- 368
- 5
- 22
-
How are you checking to see if env is undefined? – Alex Booker Jul 23 '15 at 18:39
-
process.env.NODE_ENV – Oleg Baranovsky Jul 23 '15 at 18:40
-
If you open a blank command-prompt and you write `SET NODE_ENV= "development"` and then `echo %NODE_ENV%`, what is the result? – Alex Booker Jul 23 '15 at 18:41
-
I would suggest assuming development unless the NODE_ENV is set to production, allowing you to not care if your dev environment has said variable. – Kevin B Jul 23 '15 at 18:42
-
"development" but in the project undefined – Oleg Baranovsky Jul 23 '15 at 18:43
-
I try to use logger but he should know what the env – Oleg Baranovsky Jul 23 '15 at 18:46
-
that shouldn't require the env var to be set outside the application, what logger are you using? – Kevin B Jul 23 '15 at 18:49
-
I'm using winston ENV = process.env.NODE_ENV; ... level: ENV == 'development' ? 'debug' : 'error', – Oleg Baranovsky Jul 23 '15 at 18:52
-
1`ENV = process.env.NODE_ENV || 'development';` – Kevin B Jul 23 '15 at 18:57
-
Thank you very much, it works! But is there some solution for getting env from process.env.NODE_ENV I use this log log.info('Express server listening on port ' + port + ' in ' + process.env.NODE_ENV + ' mode'); and every time before mode there is undefined – Oleg Baranovsky Jul 23 '15 at 18:59
-
yes, properly set the environment variable. :) I'd suggest finding documentation on that subject based on what OS you're using. – Kevin B Jul 23 '15 at 19:02
-
1@OlegBaranovsky can you try this create a file env.js with this line console.log(process.env.NODE_ENV); Then from the command prompt >set NODE_ENV=development >node env.js – bluesman Jul 23 '15 at 19:03
-
https://technet.microsoft.com/en-us/library/Cc755104.aspx – Kevin B Jul 23 '15 at 19:05
-
@ bluesman yes I did it and result is undefined – Oleg Baranovsky Jul 23 '15 at 19:06
1 Answers
2
Solution:
"scripts": {
"start": "set NODE_ENV=development&& node app.js"
}

Oleg Baranovsky
- 368
- 5
- 22