NodeJS course - cannot update Enviornment Variables

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??

1 Like

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 :slight_smile:

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.

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

  2. The methods for setting an environment variable on CMD and powershell are different.

On CMD

set <var>=<value>

On powershell

$env:<var>="<value>"
2 Likes

Hello @yairtete,

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.

1 Like

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