Basic Node and Express - Use the .env File

*Tell us what’s appening:
Describe your issue in detail here.

I am working on the " Use the .env File" activity. I am implementing the code on REPL.IT. I believe the code is correct. When accessed directly from Chrome browser a correct JSON file is returned ({“message”:“HELLO WORLD”}).

From the freecodecamp web page I encounter:

// running tests The response of the endpoint /json should change according to the environment variableMESSAGE_STYLE (Test timed out)

// tests completed

The source code is:

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

Your project link(s)

solution:

https://replit.com/@js_aisd/boilerplate-express

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Firefox/102.0

Challenge: Basic Node and Express - Use the .env File

Link to the challenge:

The response object should either be {"message": "Hello json"} or {"message": "HELLO JSON"} , depending on the MESSAGE_STYLE value.

Is that what you are returning?


https://replit.com/@js_aisd/boilerplate-express

Also, just to be sure you have to submit this link (without /json)

https://boilerplate-express.js-aisd.repl.co
1 Like

Yes, from the original posting I a returning {“message”:“HELLO WORLD”}. I can verify the correct response is occurring by accessing the URL: https://boilerplate-express.js-aisd.repl.co/json.

I get your point. I err’ed in the cut and paste to the original error report. My bad. The problem is still there.

My code is returning {“message”:“HELLO JSON”}

It is from the code
app.get(“/json”, function (req,res)
{
if (process.env.MESSAGE_STYLE===‘uppercase’) {
response = “Hello JSON”.toUpperCase();
}
else {
response = “Hello json”;
}
res.json({
“message”: response
});

The error report from freecodecamp is:
// running tests
The response of the endpoint /json
should change according to the environment variable MESSAGE_STYLE
// tests completed

I stopped and started REPL.IT. Is there something I should do on freecodecamp? When you say “passes” - was that from looking at browser output, or are you able to somehow run it from within freecodecamp’s test?

https://boilerplate-express.js-aisd.repl.co/json
By the way, thanks for taking the time to look at this. You are a gem of a programmer.

Which argh! I had just deleted to try " nelly.lele91" approach to solving.

Yeah, I am sorry. I am thrashing now. Wasting everyone’s time at this point. It will take me a bit to walk back to where I was. You should probably go do something productive. I don’t feel I am being productive at this moment.

Just to repeat this again. The URL you submit should not have the /json path.

Eh? But is that not required for the routing?

For all the tests it works like that. You never submit the path just the root URL. The test will use the root URL as the starting point for any fetch it makes to the backend and whatever path it needs to test.

Ah. That would explain it. I missed it, that would be it.

Thanks guys, for your outstanding patience.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.