Basic Node and Express - Use the .env File

Tell us what’s happening:
Not able to pass the env test its always failing.

Describe your issue in detail here.
I have followed most of the steps as mentioned and syntax and code is looking good. Below is my code.


app.get("/json", function(req, res) {
  const messageStyle = process.env["MESSAGE_STYLE"];
  
  if (messageStyle === "uppercase") {
    res.json({
      message: "Hello Json".toUpperCase()
    });
  } else {
    res.json({
      message: "Hello Json"
    });
  }
});

Your project link(s)

solution: https://boilerplate-express--ashishmishra96.repl.co

Your browser information:

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

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

Link to the challenge:

I have added tired making changes in the code as well and updated it to below.

app.get("/json", function(req, res) {
  const messageStyle = process.env["MESSAGE_STYLE"];
  let response;
  if (messageStyle === "uppercase") {
    response = "Hello Json".toUpperCase();
  } else {
    response = "Hello Json";
  }

  res.json({
    message: response
  });
});

Hi there and welcome to our community!

The response object should either be {"message": "Hello json"} or {"message": "HELLO JSON"}

Check your responses carefully. There’s a tiny discrepancy.

Thank you for your help it was just changing Json to json and it runned.

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