Trouble Passing "Use the .env File" Lesson

Tell us what’s happening:
I am having issues getting the freecodecamp tester to give me a pass on the test. I am able to get the correct output from (bas-url)/json but for some reason it still fails the test…

Your code so far

var message = 'hello json';

if(process.env.MESSAGE_STYLE === 'uppercase'){
  message = message.toUpperCase();

app.get('/json', function(req, res){
  return res.json({"message": message});



Your browser information:

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

Challenge: Use the .env File

Link to the challenge:

var message = 'hello json';. Perhaps try changing this to var message = 'Hello json'; as I see that in the previous challenge that word is capitalized.

Just a blind guess tho.

Hi @Larquist

try putting the test inside the /json route handler:

app.get('/json', function(req, res) {
     var msg = process.env.MESSAGE_STYLE === 'uppercase' ? message.toUpperCase() : message;
     return res.json(msg);

This didn’t work for me but I was thinking the same thing!

Not quite. For some reason it didn’t like the one line if statement. It would just keep loading in the browser. I had to do it like this…

app.get('/json', function(req, res){
  var message = 'Hello json';
  if(process.env.MESSAGE_STYLE === 'uppercase'){
    return res.json({"message": message.toUpperCase()})
    return res.json({"message": message})

And it worked! Thanks though, you put me on the right track!


Thanks. It worked. I was struggling for hours