UPDATE: finally managed to solve, will update later. No need for anyone to waste their time trying to help, unless you feel like doing a little debugging practice!
Half the time when I post here, the solution simply comes to me about 30 seconds after posting, so here’s hoping. Anyway, I’ve been stuck with this one for a while and I just can’t figure out what is wrong (seeing as ‘{“message”: “Hello json”}’ does display, I’m guessing that process.env.MESSAGE_STYLE
is not being accesed for some reason, but everything looks OK, the file is correctly named and in the root folder. Any help will be much appreciated.
Exercise summary:
Create a
.env
file in the root of your project directory, and store the variableMESSAGE_STYLE=uppercase
in it.
Then, in the/json
GET route handler you created in the last challenge accessprocess.env.MESSAGE_STYLE
and transform the response object’smessage
to uppercase if the variable equalsuppercase
. The response object should either be{"message": "Hello json"}
or{"message": "HELLO JSON"}
, depending on theMESSAGE_STYLE
value. Note that you must read the value ofprocess.env.MESSAGE_STYLE
inside the route handler, not outside of it, due to the way our tests run.
Failed test message:
" The response of the endpoint /json
should change according to the environment variable MESSAGE_STYLE
"
Relevant snippet.
app.get("/json", function(req, res){
if(process.env.MESSAGE_STYLE==="uppercase"){
res.json({"message":"HELLO JSON"})
}else{
res.json({"message":"Hello json"})
}
})
My screen:
Project link:
solution: https://3000-freecodecam-boilerplate-2bhim2a2ctj.ws-us108.gitpod.io
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36
Challenge Information:
Basic Node and Express - Use the .env File