Basic Node and Express - Use the .env File


So, I have been stuck on this task for 2 days now. I still can’t solve the problem.

I keep getting “not found” output.

I have created the SECRET file in Replit, yet, I can’t seem to access my MESSAGE_STYLE variable in the myApp.js file.

Here’s my code so far;

app.get('/json', function (req, res) {
  let response = "Hello json";

if(process.env.MESSAGE_STYLE === "uppercase;") {
    res.json({"message": response.toUpperCase()})
else {res.json({"message": response})}

Any help would be appreciated. So that I can move ahead to the next challenge.:pray::pray:

Your browser information:

User Agent is: Mozilla/5.0 (Linux; Android 11; TECNO LC7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/ Mobile Safari/537.36

Challenge: Basic Node and Express - Use the .env File

Link to the challenge:

your code seems correct, maybe please post the link to your code?

Here’s the link to my code

boilerplate-express-3 - Node.js Repl - Replit

you have two handlers on the same route

app.get("/json", function (req, res) {
  res.json({"message": "Hello json"})

app.get('/json', function (req, res){
  let response = "Hello json";
if(process.env.MESSAGE_STYLE === "uppercase;") {
    res.json({"message": response.toUpperCase()})
  } else {
  res.json({"message": response})

only one of them execute…

I commented out the first handler. I still get the same output.

Do I erase the first handler altogether?

what’s in your secrets tab?

I have the MESSAGE_STYLE key and I set its value to “uppercase”.

Without quotes?

If that’s it, I have no idea why it doesn’t passes.

no wait, I know
what do you have in the quotes here?

Yeah. Without quotes.

Sorry, but I do not quite get the other question.

check what you have in the quotes, what are you comparing the variable to?

I’ve checked.
I have uppercase in there.

The secrets file has uppercase as value. It’s same with the process.env.MESSAGE_STYLE comparison

don’t you have an extra character inside the quotes?

The semi-colon.

I removed it. Same output.

what link are you submitting?

because with this last change, I can submit your live app url link and pass

at this point it can be also a cache issue, if it keeps not passin try to hard reload the freecodecamp site

1 Like

The live link that appears after i run the code.

It displays “not found”

However, I submitted like that but it didn’t pass.


I refreshed and resubmitted.

It’s passed now!

Thank you!

1 Like

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