Install and Set Up Mongoose error in npm run

I am using the gitpod virtual machine and followed the instructions to the letter after adding the url in the .env file and creating the connect method

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

let mongoose = require('mongoose')
mongoose.connect(process.env.MONGO_URI, { useNewUrlParser: true, useUnifiedTopology: true})


i am getting this error in the terminal when i am trying to run the npm

gitpod /workspace/boilerplate-mongomongoose (main) $ npm run start

> fcc-mongo-mongoose-challenges@0.0.1 start
> node server.js

Your app is listening on port 3000
(node:1139) [DEP0170] DeprecationWarning: The URL mongodb://**********:***********r@freecodecamp-shard-00-00.nwttg.mongodb.net:27017,freecodecamp-shard-00-01.nwttg.mongodb.net:27017,freecodecamp-shard-00-02.nwttg.mongodb.net:27017/?authSource=admin&replicaSet=atlas-14igxv-shard-0&retryWrites=true&w=majority&appName=freecodecamp&ssl=true is invalid. Future versions of Node.js will throw an error.
(Use `node --trace-deprecation ...` to show where the warning was created)

ps i covered my username and password but in the url in .env input it’s correct

It is just a deprecation warning. If your code does not pass a test, that warning has nothing to do with it.

Make sure you are submitting the correct URL from the preview window, the one that starts with https://3000-


You can make the warning go away by updating Mongoose and removing the options object from connect, but that will break the tests because the callback syntax used has been removed from Mongoose 7 and above, so you can’t do that.

It does look like Mongoose version 6.12.9 is using a Node driver that doesn’t throw that deprecation warning and still supports the callback syntax. You will get a different deprecation warning about strictQuery though but that is just how it is (get used to seeing deprecation warnings, they are just part of development).

1 Like