Tell us what’s happening:
Hello everyone,
I was developing code that received an .env
file, read its value, compared this value between two possibilities and returned the right one. In my tests on Insomnia this value is returned right, but it fails the freeCodeCamp test.
Does anyone have any idea why?
.env file:
{
'MESSAGE_STYLE': 'uppercase'
}
Code:
app.get('/json', function(req, res) {
const mySecret = process.env['MESSAGE_STYLE']
let message = 'Hello json';
let response;
if (mySecret === 'uppercase') {
response = message.toUpperCase();
} else {
response = message;
};
res.json({response});
});
freeCodeCamp test error message:
The response of the endpoint /json
should change according to the environment variable MESSAGE_STYLE
.
Your project link(s)
Solution: boilerplate-express-1 - Node.js Repl - Replit
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.5112.102 Safari/537.36 Edg/104.0.1293.63
Challenge: Basic Node and Express - Use the .env File
Link to the challenge: