4

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.

2
  • 1
    The variable won't propagate automatically to currently running processes. Close relevant processes (console windows, IDEs, etc.) and open them again. Commented Apr 18, 2019 at 15:09
  • Hey thanks, it works. Commented Apr 18, 2019 at 15:13

1 Answer 1

5

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. )

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.