Back End dev and API - Use the .env file

Why are tests not passed with this code.

app.get("/json", function(req, res) {
  var response = "Hello json";
  if (mySecret === "uppercase") {
    response = response.toUpperCase();
  res.json({"message": response});

Project link(s)


Challenge: Use the .env File

Link to the challenge:

As soon as I changed res.json({“message”: response}); to return res.json({“message”: response}); tests passed.

But I do not understand why return is needed…

Hello there,

Where is mySecret defined? If it is outwith the get callback function, then the code will not pass.

There should be no need for a return.

Right - why does mySecret need to be defined within the get callback function?

I go through the explanation here:

There is more detail in following replies.

Hope this helps

Thanks for the clarification.

I thought mySecret would be a global variable if defined at the beginning of myApp.js and outside any route. Therefore it would have held current value of process.env.MESSAGE_STYLE and it would be available within any Route.