Tell us what’s happening:
I’m not sure I’m using the .env file properly or in the correct way. I’ve required the ‘dotenv’ package, and I checked the spelling on everything so it should work. However, when i copy paste the whole mongo URI to myApp.js directly it works perfectly fine. It also works fine when i commit the .env file to the repo but I dont think i need to do that because it publicly exposes the URI. Could someone help me on how I can use the .env without having to commit it. It’s also defined in the .gitignore that .env files should be ignored, so im really confused why it works when I commit to the repo
Ok I got it to connect to the database, I can tell because it’s connected during the time I deployed to heroku, but for some reason it’s not passing the test on freeCodeCamp. I am not sure what is causing this. Please help
Create a .env file and add a MONGO_URI variable to it. Its value should be your MongoDB Atlas database URI. Be sure to surround the URI with single or double quotes, and remember that you can’t use spaces around the = in environment variables. For example, MONGO_URI='VALUE'
Yes I know that is what I need to do. However when I log to the console the value of the variable I want to use (console.log(process.env.MONGO_URI)) I get undefined but when I log just console.log(process.env) I get a long list of different values.