.env file challenge

Tell us what’s happening:

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

}

Your code so far

Your browser information:

User Agent is: Mozilla/5.0 (X11; CrOS x86_64 13505.63.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36.

Challenge: Use the .env File

Link to the challenge:

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).


In general, for Express.js apps, it is an anti-pattern to have multiple definitions for the same route.

Also, in this case, it is the reason for not meeting the challenge requirements. The challenge expects the response to change, based on the current state of the MESSAGE_STYLE environment variable.

As it stands, the response will only be defined once (at runtime). After this, the response will be the same, no matter what the environment variable is.

Hope that clarifies.

what am I supposed to do? what am I missing?

I have been trying every solution possible and nothing works. I need help please

That code runs once, at runtime. So, whatever MESSAGE_STYLE is at runtime, that will define the /json callback.

The tests change the value of MESSAGE_STYLE. So, your code needs to change based on a change of MESSAGE_STYLE.


To summarise, you have an issue of logical order of operation. At runtime, this code runs, and the result is:

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

That means, when the tests change MESSAGE_STYLE, your response does not change. This is the problem.

You have posted a screenshot without saying anything, and have not changed your code since the first post…

The more information you give us, the more likely we will be able to help. We will not post solutions, but help you realise the answer on your own terms. This is a learning platform, not a solution/homework solving platform.

yes I know … i keep on changing it and the message I get is “not found” or when i paste the link it doesn’t pass. Are there some type of hint or example if thats possible

Would you mind pasting a link to your project code?

https://repl.it/@AlcidesGomez/boilerplate-express#myApp.js

You appear to have deleted all the code from the previous challenges. That is why nothing is showing up, when you RUN the app.

I highly recommend you start from scratch to make sure you understand the concepts, and what the instructions expect.

How do I start all over again? Is there an option in how re-do those lessons again?

You can go to the first lesson, and re-clone the boilerplate by doing one of the following:
A) Clicking on the repl.it link provided
B) Manually cloning the boilerplate repo from GitHub, and importing it into Repl.it or any other service you like.

Hope this helps. Keep at it, it will make sense, eventually :smiley:

Thank you for your help and I apologize for repeating myself so many times

No worries. We all can improve on our communication skills. So, keep asking questions, if you have them - it is why this community is here.

Hi I am trying redo the Node & Express challenges and it is not allowing me. So, I have no idea what else to do. Also I tried working on it on Glitch and still nothing. Can someone please help

Are you stuck at this lesson again?

Yes I am. I even tried to redo it from the start and nothing is working.

I cannot see the whole error in the console, but it is an error with your app, and not freeCodeCamp’s side. So, I recommend you carefully look at the error, to get an idea of what the problem is.

Potentially, you should run npm install again.