Basic Node and Express - Use the .env File - wrong instructions

“The .env is a shell file, so you don’t need to wrap names or values in quotes.”

from this lesson

but if you don’t wrap the value in ‘quotes’ it doesn’t work. Maybe there was a patch?

process.env.MESSAGE=uppercase – doesn’t work

process.env.MESSAGE=‘uppercase’ – works

It looks like you are assigning the variable in the wrong file.

You should make the modification in the .env file. process.env... is what you use to call the variable from the appropriate .js file.

Neither process.env.MESSAGE=uppercase nor process.env.MESSAGE='uppercase' make sense.

Oh you’re right. “Store the variable MESSAGE_STYLE=uppercase in the .env file.

Looks like I didn’t follow instructions properly.

However it looks like you can assign variables using process.env.VARIABLE_NAME from within myApp.js.

is it bad practice to declare env files anywhere besides the actual env file itself?

I don’t know what affect that would have to be honest.

The whole point of env variables though is to keep secrets out of your code - passwords, API keys, database addresses, that kind of thing.

Setting them in the app is pointless - you’re just setting a local variable at that point anyway.

1 Like

I understand now!

Thanks Jackson :smile:

1 Like