Environment variables challenge

Tell us what’s happening:
i’m getting the requested results but the test is not passing. i don’t know why

Your project link(s)

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

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.81 Safari/537.36

Challenge: Use the .env File

Link to the challenge:

Note: If you are using Replit, you cannot create a .env file. Instead, use the built-in SECRETS tab to add the variable.”

Did you do this? What did you type in there?

I already solved it. Turns out if you do the if check outside of the handler function the test fails for some reason even though you get the exact same result

You don’t get the exact same result though. If you check the environment variable in the global scope, then your app does not respond to changes to the environment variable.

1 Like

Yes it did, i checked multiple times. I changed the environment variable’s value to “asd” (without quotations of course) and the message would be lowercase

I’m sorry, but no, it did not.

Placing the line of code where you check the value of the environment variable outside of the handler function means that the environment variable is checked only once, when the application first starts.

However, when you check the value of the environment variable inside the handler function, then you check the value of the environment variable every time the handler function is called.

This difference is important because the test suite sends a command to your application to change the environment variable while the application is running. If you do not check the value of the environment variable inside of your handler, then it is literally impossible for your handler to respond to this change.

Manually changing the environment variable involves restarting the application, which isn’t how the test suite works. It also isn’t how you would want a real world application to work. You shouldn’t need to restart the application to change this behavior.

1 Like

Aahh yes, i understand now. I guess i completely missread that in the challenge description. Thank you for responding

No worries. It took me a while to figure out what was up the first time I saw someone have ttis issue since I’ve not done a lot of this sort of development.