MongoDB and Mongoose - Install and Set Up Mongoose

MongoDB and Mongoose - Install and Set Up Mongoose
0

#1

Hi! I’m doing the first exercise from the “Mongo DB and Mongoose” section, but Glitch trows me the error " Error: Cannot find module ‘mongoose’ ".
My code for the dependencies on package.json is:
[…]
“dependencies”: {
“express”: “^4.16.3”,
“body-parser”: “^1.18.3”,
“mongoose”: “^5.1.6”,
“mongodb”: “^3.4.13”
},
[…]

And the code on MyApp,js:
[…]
const mongoose = require(‘mongoose’);
mongoose.connect(process.env.MONGO_URI);
[…]

Any idea of what is wrong?


#2

Hi!

I tried your code and cannot replicate the error. May you post all the code?


#3

The complete code of package.json is

{
  "name": "fcc-mongo-mongoose-challenges",
  "version": "0.0.1",
  "description": "A boilerplate project",
  "main": "server.js",
  "scripts": {
    "start": "node server.js"
  },
  "dependencies": {
    "express": "^4.16.3",
    "body-parser": "^1.18.3",
    "mongoose": "^5.1.6",
    "mongodb": "^3.4.13"
  },
  "engines": {
    "node": "4.4.5"
  },
  "repository": {
    "type": "git",
    "url": "https://hyperdev.com/#!/project/welcome-project"
  },
  "keywords": [
    "node",
    "hyperdev",
    "express"
  ],
  "license": "MIT"
}

The only thing I add to myApp.js is

const mongoose = require('mongoose');
mongoose.connect(process.env.MONGO_URI);

The rest of the code in that file is the Glitch code that was there when I open the project from the FreeCodeCamp section.

The code in .env is

SECRET=
MADE_WITH=
MONGO_URI=mongodb://XXXX:[email protected]:49818/pruebabeloqui

where the Xs are the user and password of the database.


#4

According to your error ,node is not abale to find the mongoose module so you can try this .

  1. First check whether you have multiple version or not . Sometime problem occur due to that .
  2. Re install all module for the project .

Then check in node shell for the mongoose .


#5

I changed my dependencies to

"mongoose": "^5.1.6",
"mongodb": "^3.0.10"

and now it works. Thank you!


#6

I had a problem in that my password used a key that wasn’t supported in the .env file. That character was one of these = [email protected]#$%^&*()

To solve it, I made another user, set the password to not contain one of the above symbols and then deleted the old user. When I just used numbers and letters in my username and password, I passed the tests.

Hope this helps! :smiley:


#7

It also looks like you can’t use colons in your password, either. So can we only use letters and numbers?

EDIT: You can also use underscores…


#8

It’s helpful, thank.


#9
    "mongodb": "*",
    "mongoose": "*"