Stuck on this annoyingly simple problem for months 😡

Tell us what’s happening:

I am stuck on this stupid problem for months now. It’s trivially simple, but I am unable to pass it. I don’t know if this is a bug in my code, or a bug with FCC.

The challenge: https://www.freecodecamp.org/learn/apis-and-microservices/basic-node-and-express/use-the--env-file

My code: https://glitch.com/~eastern-earthy-rake

As you can see at https://glitch.com/~eastern-earthy-rake/json, my code does post HELLO JSON in uppercase.

I get the error: The response of the endpoint /json should change according to the environment variable MESSAGE_STYLE

What am I doing wrong here?

Your code so far

let message = {“message”: “Hello Json”}

/** 6) Use the .env file to configure the app */

app.get(’/json’, (req, res)=> {
if (process.env.MESSAGE_STYLE === ‘uppercase’) {
res.json ({“message”: “HELLO JSON”})
} else {
res.json (message)}
})

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36.

Challenge: Use the .env File

Link to the challenge:

1 Like

Try this one:

app.get(’/json’, (req, res)=> {
if (process.env.MESSAGE_STYLE === ‘uppercase’) {
res.json ({“message”: “HELLO JSON”})
}
res.json (message)
})
1 Like

Nope, it doesn’t work. I get the same error.

I had posted about my problems with this challenge in June. I’m still stuck on this challenge.

1 Like

Try now:

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

(damn i hate the formatting shortcuts here XD)

But just to be clear, your code looks fine (although Im no expert) it’s a matter of giving the algorithm what he wants.

If it does not pass, would you let me know whats your .env file like?

1 Like

Screenshot of my .env file:

image

I don’t know exactly whats that, but I would create a simple .env file in your directory, just next to the app.js

1 Like

The test did not pass :frowning:

Can you link me to the repl? if that’s possible, so I can see your files

1 Like

Sure: https://glitch.com/edit/#!/join/ae3646b9-6d8d-418f-a6fa-96d0cf0d17c8

That’s not what I mean. But the page where you’re actually writing the code (or maybe there are more ways to use glitch than I knew of).

1 Like

Something like this https://repl.it/@misterybodon/boilerplate-express

also, check out how I approach the problem and see if we’re doing similar

1 Like

I tried to submit your solution, and I get the same error. Does this happen to you?

You need to update the fCC dependency in your project. Remove the fcc-express-bground-pkg.git package and then add it back again.

Delete this line from package.json

"fcc-express-bground": "https://github.com/freeCodeCamp/fcc-express-bground-pkg.git"

Wait for it to uninstall, then add it back (put back the line you remove) and let it install. Now submit the project.

1 Like

Thats not the link for the solution, only for the repl.

This is the link:

https://boilerplate-express.misterybodon.repl.co

yes as @lasjorg says thats also part of the problem as can be checked using

> npm outdate 
//output
Package              Current  Wanted  Latest  Location
fcc-express-bground    0.0.5     git     git  fcc-learn-node-with-express

(but they should tell this in the exercise description)

I believe npm update should do, though. Or maybe not?

2 Likes

That worked! Thank you.

Thanks for the assist. You cannot imagine how frustrating it has been to deal with this challenge. I gave up on the whole track, worked on a different certification, came back after a few months again to this…

You’re welcome and am quite sad about that, checked out your profile and saw the question many times therein. Feel free to ask me in a message any other time. Though I wasn’t that helpful.

Good luck!

1 Like

@slashgod Good to hear, sorry for the inconvenience. Happy coding.


Just as an FYI. This issue will affect anyone that has started the project before the package was updated. The update to the package was made to deal with a recent issue with Glitch. I only knew this was the issue because I recognized the console error and I made the PR with the fix.

1 Like

Thanks. It worked. I was stuck too.