Cannot Pass Test: Use .env File Section

Tell us what’s happening:
I cannot pass test in Use .env File section even I followed the steps and got the same result



var express = require('express');
var app = express();



const mySecret = process.env['MESSAGE_STYLE']

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

});

Your project link(s)

solution: https://replit.com/@yinnsu/boilerplate-express-2

Your browser information:

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

Challenge: Use the .env File

Link to the challenge:
https://www.freecodecamp.org/learn/back-end-development-and-apis/basic-node-and-express/use-the--env-filePreformatted text

1 Like

Welcome there,

You are not really following this section of the instructions:

…in the /json GET route handler you created in the last challenge…

Hope this helps

2 Likes

"uppercase " you have a space at the end.

1 Like

I am also having trouble passing this question.

That’s my code:

const mySecret = process.env[‘MESSAGE_STYLE’]

app.get(’/json’, function(req, res){
if(mySecret == ‘uppercase’) {
res.json({message: “HELLO JSON”});
}else {
res.json({message: “Hello json”});
}
})

and I see my code works here https://boilerplate-express-5.samtaitai.repl.co/json
but I cannot pass the test. Please help!

@samtaitai You need to move const mySecret = process.env['MESSAGE_STYLE'] inside the app.get handler function.


BTW, in the future, if you have a question please open a new thread.

1 Like

passed it, thank you!