Node .env file challenge won't pass

Hi, I’ve got a problem with the “Use the .env File” node challenge. My code works fine (i.e. if I go to my Glitch live app I can see that it works as it should) but the test just won’t pass, failing with a " The response of the endpoint /json should change according to the environment variable MESSAGE_STYLE" error, which is infuriating to put it mildly. The relevant code is:

let message = "Hello json";

message = process.env.MESSAGE_STYLE == "uppercase" ? message.toUpperCase() : message;

app.get("/json", (req, res) => res.json({"message": message}));

I’m honestly getting kinda tired of wasting my time because of FCC’s badly written tests; this is not the first time something like this has happened but it is the first time I’m unable to fix it. Can someone just post code that actually passes the f*** test? Believe me, I’ve googled and tried every piece of code people have posted here and nothing worked.

Hi. Question: is your .env file correctly written?

Yes, it was (which, BTW, can be misleading for beginners, because the challenge is worded in such a way that it leads one to believe the “.env” file should be already there instead of having to create it). I’m not sure what the error was, but I was able to pass the test by doing the following:

  1. Clone a new Glitch from the URL they give in the introduction (my guess is something glitchy -heh- happened with my Glitch, because I realized my “myApp.js” file was missing). Is it just me or is Glitch terribly buggy? Half the times I try to clone from that URL it just doesn’t work (i.e. it gives me an empty Glitch).
  2. The following code seems to pass the test, though I’m not sure why (maybe the strict equality operator? Who knows):
app.get("/json", function(req, res) {
  if(process.env.MESSAGE_STYLE === "uppercase") {
    return res.json({"message": "HELLO JSON"});
  } else {
    return res.json({"message": "Hello json"});
  }
});

I really dislike this solution because it’s inelegant (needless code repetition), but oh well, at least it passes the test.

Just by first glance…try triple equals in your first try.

Up to that point, I remember having to figure out more things which aren’t told in the challenge explanation.
I think that shouldn’t discourage you, since in a real project you will have to decide, discover and amend a lot of things by your own, don’t you think? Also, you have the forum and the Read-Search-Ask method if you get stucked.

I know. Like I said, this isn’t the first time some FCC test refused to pass. Researching stuff is all fine and dandy, but one shouldn’t tout what is clearly a FCC weakness (strict and/or buggy tests which are not clearly stated in the challenge) as a virtue.

You shouldn’t use that kind of language with people who are spending their time teaching. FCC is putting a lot of curated content at our fingertips without asking you for anything in return.

Errors like this occur in many courses, both free and paid.
I know it is frustrating when this kind of thing happens, I have experienced it here and in many other courses and tutorials. Testing code is not easy and FCC builds a free platform and does not ask you for anything in return, it does not ask you to invite friends to unlock functions, it does not force you to see ads.

Quincy Larson and the many collaborators who work to maintain and improve FCC do not deserve unpleasant language. What they all deserve is our great thanks and great applause.

My suggestion is that if you find a BUG like this report it and be part of the wonderful community that makes it great and improves FCC day by day allowing many people around the world to learn to program.