alex
alex

Reputation: 65

windows environment variables not being returned in node.js

I have set the environment variable for windows as follows:

setx port 8080 /M 
#prints out the expected output
echo %port% 

And have following code in my file.js

const port = process.env.PORT;  
console.log(port); 

But it always prints out the value as undefined and my application does not start, despite the fact that this environment variable exists in my system. Thank you for your help.

Upvotes: 4

Views: 1328

Answers (1)

mukund
mukund

Reputation: 603

I have had same problem while running my node application on windows. Restarting your IDE should solve this problem. (in my case I restarted visual studio code and intergrated terminal and it could already recognize recently set environment variables. )

Upvotes: 5

Related Questions