# freeCodeCamp Challenge Guide: Install and Set Up Mongoose

**URL:** <https://forum.freecodecamp.org/t/freecodecamp-challenge-guide-install-and-set-up-mongoose/301540>\
**Category:** freeCodeCamp Contributors\
**Tags:** guide\
**Created:** [August 3, 2019, 1:13pm UTC](https://forum.freecodecamp.org/t/freecodecamp-challenge-guide-install-and-set-up-mongoose/301540 "2019-08-03T13:13:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![camperbot](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/camperbot/32/18364_2.png) [@camperbot](https://forum.freecodecamp.org/u/camperbot)\
**Post date:** [August 3, 2019, 1:14pm UTC](https://forum.freecodecamp.org/t/freecodecamp-challenge-guide-install-and-set-up-mongoose/301540/1 "2019-08-03T13:14:00Z")

</div>

# [Install and Set Up Mongoose](https://www.freecodecamp.org/learn/apis-and-microservices/mongodb-and-mongoose/install-and-set-up-mongoose)

* * *

## Problem Explanation

You might want to check both the [MongoDB](https://www.npmjs.com/package/mongodb) and the [Mongoose](https://www.npmjs.com/package/mongoose) NPM Repositories for the manual configuration if you are not using Giltch.

OR

1. You can use the glitch feature of search packages, install them and update package.json all by itself. (You should use fresh Glitch project from the url given in MongoDb and Mongoose first intro page).

2. Once done add the MONGO\_URL in .env file and assign your path as

```auto
mongodb://<dbuser>:<dbpassword>@ds<PORT>.mlab.com:<PORT>/<DATABASE-NAME>

```

which you copy from MongoDB Atlas. Remember to remove the angle brackets `< >` when you replace your username and password of your database. Make sure to surround the entire url in single quotes.

* * *

## Hints

### Hint 1

**Timeout error**

If the tests are timing out, check the `package.json` file. Ensure the final dependency does not end in a `,`.

For example, this will result in a timeout error:

```auto
"dependencies": {
  "express": "^4.12.4",
  "body-parser": "^1.15.2", 
},

```

### Hint 2

**add MONGO\_URI to .env**

- Insert a line that looks similar to:

```auto
MONGO_URI='mongodb+srv://<username>:<password>@<clustername>-vlas9.mongodb.net/test?retryWrites=true`

```

`<username>` and `<clustername>` will be automatically generated by MongoDB.

- Replace `<password>` with your password. There should be no `<>` characters (unless those are in your password).

Still having issues? Check the below hints:

- Remove spaces before and after `=`.  
CORRECT:

```auto
MONGO_URI='mongodb...'

```

INCORRECT:

```auto
MONGO_URI = 'mongodb...'

```

- Do you have symbols or special characters in your password, e.g. `$&(@`? If so, you will need to translate these into unicode. MongoDB has instructions on how to do this. I would suggest changing your password to be letters and numbers only for simplicity.

* * *

## Solutions

> **Solution 1 (Click to Show/Hide)**
>
> **.env**
> 
> ```auto
> GLITCH_DEBUGGER=true
> # Environment Config
> 
> # store your secrets and config variables in here
> # only invited collaborators will be able to see your .env values
> 
> # reference these in your code with process.env.SECRET
> SECRET=
> MADE_WITH=
> MONGO_URI='mongodb+srv://<username>:<ENTERYOURPASSWORDHERE>@<clustername>-vlas9.mongodb.net/test?retryWrites=true'
> # note: .env is a shell file so there can't be spaces around =
> # The entire url should be surrounded by single quotes
> 
> ```
> 
> **package.json**
> 
> ```json
> {
> "name": "fcc-mongo-mongoose-challenges",
> "version": "0.0.1",
> "description": "A boilerplate project",
> "main": "server.js",
> "scripts": {
> "start": "node server.js"
> },
> "dependencies": {
> "express": "^4.12.4",
> "body-parser": "^1.15.2",
> "mongodb": "^3.0.0",
> "mongoose": "^5.6.5"
> },
> "engines": {
> "node": "4.4.5"
> },
> "repository": {
> "type": "git",
> "url": "https://hyperdev.com/#!/project/welcome-project"
> },
> "keywords": [
> "node",
> "hyperdev",
> "express"
> ],
> "license": "MIT"
> }
> 
> ```
> 
> **myApp.js**
> 
> ```javascript
> /** # MONGOOSE SETUP #
> /* ================== */
> 
> /** 1) Install & Set up mongoose */
> const mongoose = require('mongoose');
> mongoose.connect(process.env.MONGO_URI);
> 
> ```

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [January 8, 2025, 3:58pm UTC](https://forum.freecodecamp.org/t/freecodecamp-challenge-guide-install-and-set-up-mongoose/301540/2 "2025-01-08T15:58:00Z")

</div>


