I’m on the section that requires a database to be set up with Mongo. I did that, and pasted my key on the MONGO_URI variable inside the sample.env file, but I’m still getting an error when trying to pass the tests.
Can someone help me find out what I’m doing wrong?
By the way, my password for the database contains a hashtag, and I’ve read that needs to be written as %23 instead.
It still isn’t working. And I’m not sure what creating a copy of the same file type will do. There’s nothing in these instructions that say to do that.
I’m honestly disappointed in the lack of instructions for these exercises.
It looks like you’re working on the challenges locally, which I’ll admit isn’t something they’re specifically designed for. That is, there are some extra steps that need to be taken.
Copying the sample.env file to the .env file is pretty common with projects - The sample.env file is designed to give a boilerplate for the secrets you’ll need for the project, and the .env file is typically ignored by version control so those secrets aren’t committed publicly. This isn’t something that I believe is mentioned in our curriculum, and it probably could be.
One thing that is covered, however, is the use of the dotenv package when working locally - it’s mentioned in this lesson. Have you installed and configured that package?
Okay. The instructions say to import the variables on app.js, but I don’t have that file in this lesson …
If you are working locally, you will need the dotenv package. It loads environment variables from your .env file into process.env . Install it with npm install dotenv . Then, at the top of your myApp.js file, import and load the variables with require('dotenv').config() .
So you’re not making a copy of the sample.env file with the same name… you need a file just called “.env”… nothing in front. That is a special file for storing “environmental variables”, which are secret things like passwords and database access stuff… that way someone can’t just view the source code of your program, and get access to all your secret stuff.
So, in the same place that your “sample.env” file is, create a new file, and just call it “.env”… it should then have a settings gear as an Icon… then copy the contents of sample.env into the .env file. Then that file is where you would also put your MONGO_URI.
In your programming code, anytime you type process.env you are accessing that .env file.
Also, as a note, once you have a “.env” file, and have put the necessary stuff in it, I’d suggest deleting your “sample.env” file, as it currently has some secret stuff in it.
Also, in this thread, might want to delete the picture you sent as it also has your database login info in it… that’s how you end up with a database full of Russian links and characters… like happened to one of my Joomla SQL databases, lol.
Are you able to share all of your code? A link to a GitHub repo would be ideal. Otherwise, if you import your code into Replit and share that link, that would be easiest.
The main points in this thread:
The sample.env file should not be used (read) by any application - it serves as a boilerplate for developers to know what environment variables (secrets) are needed for an application.
The .env file should not be committed in Git, and often contains secrets that should not be shared with anyone. In order to make use of the .env file, you usually have to use a library like dotenv to parse (read) the file, and inject the secrets into your Nodejs process (process.env). I say ‘usually’, because environments like Replit do this automatically
As you can see in your code, your app refers to a SESSION_SECRET. This should be added to your .env file.