MongoDB and Mongoose - Install and Set Up Mongoose

Tell us what’s happening:

Title: Issue Completing First Lesson Test on GitPod

Hello everyone,

I’ve successfully completed the first lesson test on Replit, but I’m unable to do the same on GitPod despite following the same steps.

I’ve:

Created a .env file with the MongoDB connection string.
Added the necessary code to myApp.js for database connection.
Ran npm run start.
On GitPod, the server port seems to be in use, or the connection isn’t recognized. Any help would be appreciated!

Thanks!

###Your project link(s)

solution: https://3000-freecodecam-boilerplate-p6hldo9k7zx.ws-us115.gitpod.io

Your browser information:

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

Challenge Information:

MongoDB and Mongoose - Install and Set Up Mongoose

i wonder if this is because on gitpod you need the dotenv package?

I recall that in the basic node and express project, the instructions would remind us to:

If you are working locally, you will need the dotenv package. It loads environment variables from your .env file into process.env. The dotenv package has already been installed, and is in your project’s package.json file. At the top of your myApp.js file, add require('dotenv').config() to load the environment variables.)

So maybe worth a try to require the dotenv package in your code for this other project too.

1 Like

thank you hbar1st for your reply. so, what i have to do is adding require(‘dotenv’).config() in myApp.js , right?

Yes that is my suggestion.

“require(‘dotenv’).config()” is already in my myApp.js file, so I didn’t need to add it. When I restart my GitPod workspace, the test passes. It seems that the server on GitPod needs extra time to execute the code.
Anyway, thank you for replying and helping me! :slightly_smiling_face: