Hello, I’m in the NodeJs course right now, and trying to update my NODE_ENV enviornment Variable with no success… every time I update it in the CMD or even Windows PowerShell it seems like it did it, and then nothing happens in the NodeJS Express Demo build in the course.
the question I guess i’m asking, is if anyone did this course, how did you cionfigure your ENV VARs??
Hi, mosh said if you’re on windows use set and if you’re on mac use export keyword to set your environment variable, i did try set keyword and nothing happend but then i used export keyword and it worked.
And coming to think of it i think i used a different command line.
So just try these and if this didn’t work come back and we’ll look into it and fix the issue
Well, export doesn’t work… and I have tried using cmd and windows powershell… no hope as of now
Is there any kind of errors or something to work on ?
Can you send a picture of your code ?
@yairtete There are two things you need to keep in mind here.
You must set the environment variable and then start the node server from that console instance itself . If you set the variable on one CMD window but open another CMD window to run your node server, it will be unable to detect the environment variable.
The methods for setting an environment variable on CMD and powershell are different.
I had the same issue, I recommend you to use dotenv to manage env variables. It’s really easy.
- Run npm i dotenv on terminal.
- Make an .env file (with only the extension) in your root directory.
- Put all your environment variables as name=value there.
Now you should be able to access them via config module.
Further reading here.
It’s a good suggestion. But if you want to have separate environment variables for dev and prod, you will need dotenv-flow.
Did you tried set?
Because it’s working fine for me with set