.env not identified with Repl and not working on others

Hi,

So I’m pretty sure the .env challenge is simply not working.
With replit - this stupid ‘secrets’ thing they have going on is just bad:
Every variable I try to get from there (obviously I create it first) is simply undefined.
It doesn’t matter if I do process.env.VAR_NAME or process.env[‘VAR_NAME’] like their code-completion/insertion thing suggests - ALL VARIABLES ARE NOT WORKING AND ARE ‘UNDEFINED’.

So after HOURS of trying to work with replit with no success, I tried with Glitch.
Which is actually working! yay! I get different messages in my /json path according to the MESSAGE_STYLE variable!
But… it seems freeCodeCamp doesn’t recognize it…
I made sure that it actually changes according to the env var and yet no response from freeCodeCamp.

Please, it’s like a 3 minute challenge that I already passed (technically) - what can I do now? is there a bug with this challenge?

solution: https://replit.com/@omerwow/boilerplate-express

Your browser information:

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

Challenge: Use the .env File

Link to the challenge:

Welcome there,

I am not sure what you are experiencing in Replit, as I cannot replicate any issues. Also, I am not sure what your Glitch code is, but with the code you linked to there is an issue:

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

Consider when the code runs:

  1. Node application starts:
  • All variables are defined (e.g. response = "HELLO JSON")
  • All routes are attached to app
  • All callbacks are defined for what should happen if a route is reached
  1. Now, a route is requested (e.g. /json):
  • The route has been defined to respond with some form of response whatever its value is
  • response is still "HELLO JSON"
  1. The environment variable is changed (the fCC tests do this for you)
  • The script is still running from previously, so response is not redefined/changed
  • The route res is always the same

Hope this helps

@OmerWow is correct… .env are no longer allowed in repl.it which is causing issues.

Have not confirmed Glitch yet.

Relevant discussion: Replit Create a .env File Changed

2 Likes

Found this topic helpful as well: Use the .env File - Issue [RESOLVED] - #17

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