Use the .env File

Hi, I have struggled with this for a while. It was working for me, but would not pass the test.

Turn out, the key thing to pass this test is to check for env variable value inside the response function.

so, this was working for me, but not passing test (in other words, changing variable value in the .env file was yielding correct results)

const message = "Hello json";
const response = (process.env.MESSAGE_STYLE === "uppercase") ? message.toUpperCase() : message;
app.get("/json", (req, res) => res.json({"message": response}));

However, you need to check the condition inside the response function:

const message = "Hello json";
app.get("/json", 
    (req, res) => res.json(
        {"message": process.env.MESSAGE_STYLE === "uppercase" ? message.toUpperCase() : message
    })
);

This is correctly passing the test for this exercise.

2 Likes