.env challenge failed

I can’t get this challenge to work, this is my code:

let message = "Hello json";

if (process.env.MESSAGE_STYLE == "uppercase"){
  message = message.toUpperCase();
}

const response = {
  "message": message
}

app.get("/json", (req, res)=>{
  res.json(response);
});

I’m using replit and I added the variable to secrets. I think the response for the /json is right but maybe I’m missing something small but important. Can you guys help me?

Your project link(s)

solution: https://boilerplate-express.chapuawe2.repl.co/json

Your browser information:

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

Challenge: Use the .env File

Link to the challenge:

I’ve just checked the console and it appears like it’s trying to reach the env variables of my replit maybe?

I think I have learned more than what the lesson was supposed to teach me.

I debugged all the code, first of all, the request to /_api/use-env-vars then I asked myself where that piece of code is, checked server.js and nope, neither in my code. So I look at the dependencies and went to the github of fcc-express-bground-pkg and looked at the code to find where that piece is.

After knowing that, I figured out that the code actually dynamically changes my env variables, and then, ONLY THEN I knew that I needed to assign the new message only when the json is called.

This is my finall and working code:

app.get("/json", (req, res)=>{
  const response = {
    "message": "Hello json"
  };

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

  res.json(response);
});

congratulations in the debugging! it wasn’t easy to figure out the issue, so that was a wonderful problem solving situation there!

1 Like