# Install and Set Up Mongoose Help Please!

**URL:** <https://forum.freecodecamp.org/t/install-and-set-up-mongoose-help-please/264477>\
**Category:** General\
**Created:** [March 12, 2019, 6:21pm UTC](https://forum.freecodecamp.org/t/install-and-set-up-mongoose-help-please/264477 "2019-03-12T18:21:59Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![chrisjohnson](https://avatars.discourse-cdn.com/v4/letter/c/48db29/32.png) [@chrisjohnson](https://forum.freecodecamp.org/u/chrisjohnson)\
**Post date:** [March 12, 2019, 6:21pm UTC](https://forum.freecodecamp.org/t/install-and-set-up-mongoose-help-please/264477/1 "2019-03-12T18:21:59Z")

</div>

Hi Everyone,

I have been stuck on this challenge for over a week trying to figure out what I did wrong. Can anyone please point out where my error is?

This is my .env file

```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://chrisjohnson0390:myPassword@ds123625.mlab.com:23625/freecodecamp_mongo

# note: .env is a shell file so there can't be spaces around =

```

This is my app.js

```auto
const mongoose = require("mongoose");

mongoose.connection.on("open", function(ref) {
  console.log("Connected to mongo server.");
});

mongoose.connection.on("error", function(err) {
  console.log("Could not connect to mongo server!");
  return console.log(err);
});

const mongoURI = "mongodb://chrisjohnson0390:myPassword@ds123625.mlab.com:23625/freecodecamp_mongo";

const db = mongoose.connect(mongoURI, { useNewUrlParser: true });

```

And this is my package.json

```auto
{
	"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",
    "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"
}

```

When I run the test this is the error that I get:

// running tests

mongoose is not connected

Unexpected token \< in JSON at position 0

Unexpected token \< in JSON at position 0

// tests completed

Any help is greatly appreciated!!

---

<div class="post-metadata">

**Author:** ![Dereje1](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/dereje1/32/63598_2.png) [@Dereje1](https://forum.freecodecamp.org/u/Dereje1)\
**Post date:** [March 12, 2019, 6:30pm UTC](https://forum.freecodecamp.org/t/install-and-set-up-mongoose-help-please/264477/2 "2019-03-12T18:30:43Z")

</div>

I’ve been noticing more of these errors on the mongoose challenges since mlab became a part of mongoDB and changed some of the connection strings, need to check with a brand new mlab account if it really is the case and affecting those challenges.

---

<div class="post-metadata">

**Author:** ![chrisjohnson](https://avatars.discourse-cdn.com/v4/letter/c/48db29/32.png) [@chrisjohnson](https://forum.freecodecamp.org/u/chrisjohnson)\
**Post date:** [March 12, 2019, 6:32pm UTC](https://forum.freecodecamp.org/t/install-and-set-up-mongoose-help-please/264477/3 "2019-03-12T18:32:59Z")

</div>

This is my second account I’ve used. I had one set up for a web developer boot camp I took recently. That account works fine connected to my app I have hosted in Heroku.

Neither account passes the test and honestly I don’t even understand what the error means!

---

<div class="post-metadata">

**Author:** ![Dereje1](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/dereje1/32/63598_2.png) [@Dereje1](https://forum.freecodecamp.org/u/Dereje1)\
**Post date:** [March 12, 2019, 6:34pm UTC](https://forum.freecodecamp.org/t/install-and-set-up-mongoose-help-please/264477/4 "2019-03-12T18:34:25Z")

</div>

post your glitch link, I’ll test it with my own mlab connection string

---

<div class="post-metadata">

**Author:** ![chrisjohnson](https://avatars.discourse-cdn.com/v4/letter/c/48db29/32.png) [@chrisjohnson](https://forum.freecodecamp.org/u/chrisjohnson)\
**Post date:** [March 12, 2019, 6:39pm UTC](https://forum.freecodecamp.org/t/install-and-set-up-mongoose-help-please/264477/5 "2019-03-12T18:39:51Z")

</div>

I just created the account for this forum so it doesn’t trust my links yet sorry! Please add the https.

://glitch.com/~petite-snout

---

<div class="post-metadata">

**Author:** ![Dereje1](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/dereje1/32/63598_2.png) [@Dereje1](https://forum.freecodecamp.org/u/Dereje1)\
**Post date:** [March 12, 2019, 6:49pm UTC](https://forum.freecodecamp.org/t/install-and-set-up-mongoose-help-please/264477/6 "2019-03-12T18:49:38Z")

</div>

Without doing any changes, your code connects to the db and passes the challenge for me using your own connection string, which you left public btw since you did not put it in your `.env` file. Check if it is an issue of access from your glitch (whitelisting, etc…), as it is not a problem with your code or connection string.

---

<div class="post-metadata">

**Author:** ![chrisjohnson](https://avatars.discourse-cdn.com/v4/letter/c/48db29/32.png) [@chrisjohnson](https://forum.freecodecamp.org/u/chrisjohnson)\
**Post date:** [March 12, 2019, 6:55pm UTC](https://forum.freecodecamp.org/t/install-and-set-up-mongoose-help-please/264477/7 "2019-03-12T18:55:21Z")

</div>

Yeah at this point I said screw it about security for the DB. I moved the code out of the env to see if that is an issue at all.

I’m back at work now and can’t acess my personal laptop so I’ll have to check later.

Thank you for looking into this!

---

<div class="post-metadata">

**Author:** ![alkapwn3d](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/alkapwn3d/32/92787_2.png) [@alkapwn3d](https://forum.freecodecamp.org/u/alkapwn3d)\
**Post date:** [March 12, 2019, 7:15pm UTC](https://forum.freecodecamp.org/t/install-and-set-up-mongoose-help-please/264477/8 "2019-03-12T19:15:50Z")

</div>

put the URI and `const db` directly after `const mongoose = require();`

also follow these [instructions in the docs](https://mongoosejs.com/docs/index.html)

---

<div class="post-metadata">

**Author:** ![jawaka72](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jawaka72/32/159028_2.png) [@jawaka72](https://forum.freecodecamp.org/u/jawaka72)\
**Post date:** [March 12, 2019, 7:18pm UTC](https://forum.freecodecamp.org/t/install-and-set-up-mongoose-help-please/264477/9 "2019-03-12T19:18:34Z")

</div>

This happened to me a couple times. I would refresh Glitch and it would work. Maybe try refreshing the page?

---

<div class="post-metadata">

**Author:** ![mscanza](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/mscanza/32/111530_2.png) [@mscanza](https://forum.freecodecamp.org/u/mscanza)\
**Post date:** [March 12, 2019, 10:05pm UTC](https://forum.freecodecamp.org/t/install-and-set-up-mongoose-help-please/264477/10 "2019-03-12T22:05:50Z")

</div>

Been having the same issue for 3 days now. I can’t get an mlab uri, I have the new uri:

mongodb+srv://mscanza:password@fcc-vcnna.mongodb.net/test?retryWrites=true;

I can’t connect to Mongoose…

Please let me know if/how you fix it!

---

<div class="post-metadata">

**Author:** ![Nerves](https://avatars.discourse-cdn.com/v4/letter/n/59ef9b/32.png) [@Nerves](https://forum.freecodecamp.org/u/Nerves)\
**Post date:** [June 2, 2019, 2:25pm UTC](https://forum.freecodecamp.org/t/install-and-set-up-mongoose-help-please/264477/11 "2019-06-02T14:25:36Z")

</div>

I have the same problem！

---

<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 17, 2021, 9:50am UTC](https://forum.freecodecamp.org/t/install-and-set-up-mongoose-help-please/264477/12 "2021-01-17T09:50:19Z")

</div>

Closed on January 17, 2021, 9:50am UTC


