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";
      "message": response

Your project link(s)


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?

Also, just to be sure you have to submit this link (without /json)
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:

The is NOT the correct response.

and neither is:

{"message":"Hello world"}.

Read the instructions that @lasjorg stated above.

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”;
“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 forked your replit and the code passes for me. Did you stop and restart the server, so app has your latest changes?

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?

When I fork your project, I have a duplicate of the code in your project. I added the necessary environment variable to the Secrets section, clicked Run, and copied/pasted the url of my project into the challenge page and submit. All the tests pass (the challenge is completed).

What url are you submitting for this particular challenge?
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.

It does appear your myApp.js looks blank now. The code you had right before it was deleted should have worked. I was going to go back and look at it one more time, but you had already deleted it.

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.