This challenge get me to installed dotenv but still it is not working

**please can some one go through my project and suggest for me… I involved dotenv package but still not working **

Your project link(s)

solution: https://boilerplate-express-2.nanasv.repl.co

Your browser information:

User Agent is: Mozilla/5.0 (Linux; Android 8.1.0; itel A16 Plus) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.93 Mobile Safari/537.36.

Challenge: Use the .env File

Link to the challenge:

I cant access your project
Did you create a .env file? Its simple, you click the button to add new file(in your main project directory) and as name you type “.env” (the file actual name is left blank, you only write its type which is env). Once you create it successfully, you should be fine following the challenge instructions.

1 Like

Yes I have, I create .env file and from inside, put the variable as instructed. Going to myApp I have this code to get the variable.

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


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



app.get("/json", function(req, res) {



  
    return res.send(message);
  
});


































 module.exports = app;

thats odd, your code seems to be working when i access your page with /json path. Maybe the test suite is getting confused. You can simplify your code a bit. You have 2 GET methods on /json which do the same thing. Get rid of one.
Also put the conditionals inside the GET callback, this might be the thing that fails

1 Like

I did as you instructed an not pass.
the link to my project.

https://boilerplate-express-2.nanasv.repl.co

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


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



































 module.exports = app;

I will appreciate if you effect the change from the link and send the link back ,so that i can see what is actually holding me thanks.

im out of guesses. Maybe its the fact your msObj is not defined in the GET body.

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

This is the code that passed the solution for me

1 Like

Thanks it works!! So challenging.