Basic Node and Express - Use the .env File - Not Found issue

Hello, best wishes and a Happy New Year community!

I’m currently working on the " Basic Node and Express - Use the .env File" exercise:

Store the variable MESSAGE_STYLE=uppercase in the .env file. Then tell the GET /json route handler that you created in the last challenge to transform the response object’s message to uppercase if process.env.MESSAGE_STYLE equals uppercase . The response object should become {"message": "HELLO JSON"} .

I’m having some issues getting the proper response in the browser, it displays “Not Found”. So I was wondering if that could be related to something wrong with my setup or something on Repl.

Here’s my code

app.get("/json", (req, res) => {
  let hello = {message: "Hello Json"};
  if(process.env.MESSAGE_STYLE === "uppercase"){
    hello.message = hello.message.toUpperCase();
  }
  res.json(hello);
});

I 've created the .env file with the variable “MESSAGE_STYLE=uppercase” inside too.

I’m kind of new with JS, so I’d be really grateful if you could provide some guidance on how to properly search issues for Node JS.

Thanks in advance for the help and patience.

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.101 Safari/537.36.

Challenge: Use the .env File

Link to the challenge:

Hi @Danilo7 :wave: Welcome back to the freeCodeCamp forums—it’s been a while!

Here are a few tips:

  • Be sure that your .env file is in the root directory of your project. You should be seeing it listed next to the other dot-files (.replit, .gitignore) in the Files tree view in your repl.it project.
  • Be sure that inside your .env file that you have MESSAGE_STYLE=uppercase, as is, without quotes of any kind.
  • Be sure that you’re repl.it project is running with the latest code, use the Stop/Run button near the top of the window to ensure it is running the latest code when you try to test it out.
  • Be sure you’re that you’re using the correct route in the URL when you test manually (i.e. project.user.repl.co/json) in your browser. The last part of the url (/json) should match the route you configured via the app.get(...) call.
  • When you provide your repl.it project url to the freeCodeCamp test you should leave off the /json
2 Likes

Hi @robertgroves! it’s nice to be back learning again!

Thanks for those tips. Actually, you were right It was missing the “/json” part from the path.

Now pointing the right direction I’m getting:

{“message”:“HELLO JSON”}

As a response, which is the right answer. However, I provided the proper path to the freeCodeCamp test (without “/json”) and it’s not working yet.

The .env file is among the other dot.files and it contains only MESSAGE_STYLE=uppercase. So that seems to be right too.

I’ll keep cheking the code to see if I can spot something missing.

Really thankful for your assistance!

1 Like

Are you sure the repl is running when you try and run the freeCodeCamp test? Double check by trying your URL (with the /json) in your browser. If you get that response in your browser then it should pass that test.

Hi, I did all the suggestion above, and still didn’t work. As soon as I click the complete button on the task’s page, my repl.it suddenly stop running and it shows this message :

SyntaxError: Unexpected token < in JSON at position 0
at JSON.parse ()

Tried many times and always get this result. Any help please?

Here’s my code anyway :slight_smile: https://repl.it/@mluthfi94/boilerplate-express

Thanks

Hi @mluthfi94 :wave: Welcome to the freeCodeCamp forums! :tada:

Unfortunately, there seems to be a known issue with this lesson’s challenge at the moment. I recommend continuing on and check back on that linked issue to see when the problem is resolved.

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