MongoDB and Mongoose - Install and Set Up Mongoose

Still trying to fix this for months, here is my live app link https://fifth-blade.glitch.me if there’s any help

I had a problem with the .env variable, and to fix it I had to add “dotenv”: “^8.1.0” as a dependency a initialize it on the server.js file, like this:

const dotenv = require('dotenv').config()

Now I can’t get the FCC challenge to evaluate my glitch url. I keep getting this and no more:

// running tests
// tests completed

I’m getting "Missing CORS headers ‘Access-Control-Allow-Origin’ on my browser console… Any ideas why this is happening???

SOLVED
I restarted the hole thing but using the github repo and not the glitch link in the instrucctions, turns out that the glitch link clones a repo that is not updated and there are a lot of things missing. Even so I had to add the “dotenv” dependency like I said before on the post, in order to get everything working!!

thank you, you saved my day !!!

Your live app link is not helpful, it just displays “OK!”

We’re you using dotenv in your local environment? You need it in your local environment but not on glitch. There is a lot of confusion about the glitch link to submit for an answer. You have to click “show” then “app in new window” and use that URL.

I have been using the link to pass other projects, but now it wouldn’t work.

One place where I made a mistake (which no one here corrects) was not adding the ‘MONGO_URI’ connect link as a string. It must be added as string in the ‘.env’ file.

MONGO_URI="mongodb://dbuser:dbpassword@ds0<PORT>.mlab.com:<PORT>/<DATABASE-NAME>"

I used try…catch statement for identifying this error and log it to the console.

try {
  const mongoose = require('mongoose');
mongoose.connect(process.env.MONGO_URI);
} catch(e) {
  console.log(e);
}

Hope that helps!

done all that before, still not working: getting this error:======= (node:2135) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

been stuck for months now, if someone can tell what am doing wrong

If you are trying to do the “Install and Set Up Mongoose” challenge it looks like you are using the wrong glitch link for the project. Your screen shots look like the link from a previous challenge in which mongoose was not used. I would start again with the link here. Also, don’t use quotes in the .env file.

Oh my God, this was my problem too. Thanks for posting!!!

This worked for me too. Thanks!

I am running the same issue where glitch is throwing error “Error: Cannot find module ‘mongoose’” .

.env
MONGO_URI=‘mongodb+srv://user998:password@cluster0-1j2di.mongodb.net/?retryWrites=true&w=majority’

myApp.js
const mongoose = require (‘mongoose’);

mongoose.connect(process.env.MONGO_URI);

package.json
“dependencies”: {
“express”: “^4.12.4”,
“body-parser”: “^1.15.2”,
“mongoDB”: “",
“mongoose”: "

THANKS!!!
Lost hours in this one.

I don’t know what to type for the database name in the .env file

mongodb+srv://:@cluster0.dyuoh.mongodb.net/?retryWrites=true&w=majority

Is it “test” like in the default hint?

Welcome, waylandchin.

For future posts, I recommend you open up your own topic, when asking about your own code/problem.

What usually happens is you choose whatever name you want for the database and collection, and, if one does not exist in your Atlas account, one will be created with whatever you put.

Hello @santiago, i can’t find my mongodb package on my package.json file. does it mean that it wont be obvious or…

This topic is outdated.

If you have a question, I recommend opening a new topic with information about your own problem.

Remember: You can use the Ask for Help button on any freeCodeCamp lesson to have a pre-populated topic opened on the forum, where you will be able to include a link to your own project, with your own code.

Cheers