Can't pass the "Use the .env File" lesson

Hello,

I’ve been working on the .env file lesson, and I cannot get the tests to pass. I have read other posts that listed numerous suggestions and solutions, but none of them are passing for me. I also read that there is sometimes a problem with glitch, so I also made my project in repl.it when I couldn’t get it to pass in glitch. The repl.it version didn’t pass either. I have attached my glitch code and my repl.it code. Does anyone have any suggestions?

Code:
https://glitch.com/~witty-desert-meteorology
https://WorrisomeAngryLaws--five-nine.repl.co

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:79.0) Gecko/20100101 Firefox/79.0.

Challenge: Use the .env File

Link to the challenge:

That one was weird. You did put the new variable in the env file, right? What it took for me to pass was to put the object values as a variable, that depending on the control statement, used the string function to modify it accordingly.

Hello there,

Try this, to debug:

  • Navigate to the server.js file
  • On line13 add the following to the array:
'https://www.freecodecamp.org', 'https://github.com/freeCodeCamp/'

Hope this helps

@CactusWren2020 I just tried putting the object values as a variable, and it still isn’t working for me. I do have the new variable in the .env file, and it’s my only variable in the .env file. @Sky020 I also tried adding those two links to the array on line 13, but the tests are still not passing.

I copied all three links to my code down below because I wasn’t sure which one would be best. I tried these new fixes in glitch and repl.it. I’m hoping to be able to get it to work in glitch because that seems like the preferred program by FCC. I’m not sure why it’s not passing, everything seems to be how it wants.

Here is my current code:

https://witty-desert-meteorology.glitch.me

Sorry, I should have realised earlier.

This looks like an error with you not having access to the environment variables.

To confirm:

  • Try to console.log(process.env.MESSAGE_STYLE)

To fix:

  • Add dotenv as a package to your package.json
  • require it with this, at the top of yourmyApp.js:
require('dotenv').config()

Hope this helps

1 Like

I’m sure @sky020 will be able to help you, but FYI I couldn’t see the .env because I’m not a part of the project. I guess that’s how Glitch is set up, the .env is for “secret” stuff.

1 Like

Thanks! I realized that I shouldn’t have ended the .env line with a “;” , apparently it made the ; part of my variable. Along with not having the dotenv package, that was likely what was causing the errors!

1 Like