Basic NodeJS/Express syntax issue

Using the .env File in basic node and express
I suspect an issue with the syntax of my code


//serving the api json data
app.get("/json", (req, res) => {
  res.json( if (process.env.MESSAGE_STYLE === "uppercase") {
  response = "HELLO JSON";
} else {
  response = "Hello json";
}
           });
});

Here is a link to the full code: https://glitch.com/edit/#!/lofty-nifty-toothpaste

Challenge: Use the .env File

Link to the challenge:

If statements don’t return anything, so this isn’t quite the syntax you want. I’d put the if statement outside of the .res, not inside.

Thank you so much for the helpful reply. Thank you. I have tried this but I think there is still an error in my code. Can you help me polish this up.

//
const response = if (process.env.MESSAGE_STYLE === “uppercase”) {
response = “HELLO JSON”;
} else {
response = “Hello json”;
}

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

Closer, but you need an object with the response as the message property.

I have tried this line of code. But it is still failing. What am I getting wrong?

`const reply = { response: “Hello json”};
if (process.env.MESSAGE_STYLE === “uppercase”) {
reply.response.toUpperCase();
} else {
reply.response;
}

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

Btw, I appreciate you taking your time to reply me.

This doesn’t change the original value of the string. It makes a new string.

You need to return the whole object. Json stands for JavaScript Object Notation.

Per the instructions, you need to see the message property

//serving the api json data
const reply = {"message": "Hello json"};
if (process.env.MESSAGE_STYLE === "uppercase") {
  reply.message = "HELLO JSON";
} else {
  reply.message;
}

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

Clearly, I am failing to understand something. But thanks for the replies. I think I will return to this another day.

Almost there. You need to determine the reply every single time git request runs. The tests work my changing the value of the environment variable.