Help with the Use the .env File challenge

Hello,

I have tried to solve this challenge for a few days and looked at the help’s and link’s to other helps and was unable to find a solution to the problem. Any help is much appreciated.

Link to my boilerplate (I think):

https://boilerplate-express-1.johnbyron.repl.co

or maybe this one:

Did you create a .env file, I did not see one in the root

app.get("/json", (req, res)=>{
//You should have res.json below the other code, or choose a 
//different way of deciding when to uppercase 
  res.json({
    "message": "Hello json"
  });

//you did not call this function, but you should just make as 
//it should be in the case of no uppercaase
  var response='Hello json'.toUpperCase;

// your res.json should be below this
  if (process.env.MESSAGE_STYLE==="uppercase"){
    response=message.toUpperCase()
  };
});

I do have a .env file, it is just above the .gitignore file. I tried it your way before and it didn’t work.

My original attempt of the solution was:

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

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

  res.json({
    "message": "Hello json"
  });
});

What is message.message also you could just use a ternary in your response. It seems like it will not show me your .env file so I will assume it is correct.

It looks like message isn’t defined in the request handler. Where is message coming from?

Okay, never mind. I read the last exercise so I can see you’re providing an object.

Here is a screen shot of my env file.

image

I saw it written that way in the first solution that I looked up when all I got were error messages. I thought that the first message was a command that I was unaware of

I verified that it works. I don’t want to give the answer away…what part are you stuck on?

I’m stuck on the Solution, lol :laughing:

Have you verified that the process.env is available?

Have you visited the route /json after passing back the updated message object?

When I name it process.env the file disappears and I can’t find it anywhere. Is that a normal thing?

You should create a file called .env
The file will only appear if you’re the owner of the REPL.

okay, so at least I did that right, lol, I’m not really sure about the route /json question

Your screenshot shows the route ‘/’. That route serves the form. You have to go to
‘your-real-url/json’

Click Open In A New Tab button next to the Url of the web page and add /json to the web address.

done, it says “message: “Hello json””

When your code is updated, it should say “HELLO JSON”. That is, when the route handler is returning the updated JSON.

Nothing has changed _____

What are you returning? What is res.json()?