I can't seem to read .env file

Tell us what’s happening:
According to the challenge, I have located the process.env file in the root folder (ie. same place as the myApp.js file. I create a variable called “response”, I use an if-statement to check if(process.env.MESSAGE_STYLE == “uppercase”) and if true, I set response to response.toUpperCase();
All that seems to work BUT the if statement. I don’t think it’s able to read the .env file?
I’ve tried to troubleshoot by logging “process.env.MESSAGE_STYLE” to the console, even as a boolean by comparing it to the string “uppercase”. In the first scenario I don’t get an output, in the second it returns “false” despite my process.env file containing the text MESSAGE_STYLE=uppercase

I’ve even tried to troubleshoot by finding another working solution from the forums and copy-pasting it into my own program, but it gives me the same errors. So I can deduct that it’s probably an issue with my .env file, either it’s location or it’s content.

Your project link(s)

solution: https://express-nodejs.andreasguldborg.repl.co

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36.

Challenge: Use the .env File

Link to the challenge:

You need the .env file named .env not process.env. Right?

.env is the extension. The name is “process” so currently my full file is “process.env”. I can’t save it “.env” (without the name) if that’s what you mean?
If you meant not to call it “process.env.env”, I’ve not done that

Why can’t you save it as a .env only ? I mean the literal name of the file is only .env

Have you checked if there’s any .env file?

The process.env.SOMETHING is the way to access .env file

Nevermind, thank you so much!
You were right.
I deleted the process.env file and created a new file just named “.env” and it worked.
I must’ve misunderstood some of the text in the challenges!

Okay :laughing: Happy coding!

1 Like

Thank you, and you too! :smiley:

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.