Mongodb using Replit

I start the Mongodb course but stuck with these errors

  • “mongoose version ^5.11.15” dependency should be in package.json

  • Failed:“mongoose” should be connected to a database

meanwhile my code in package.json is already like this (with comma because it’s not the end)

"dependencies": {
    "body-parser": "^1.15.2",
    "dotenv": "^16.0.3",
    "express": "^4.12.4",
    "mongodb": "^3.0.0",
    "mongoose": "^5.11.15"
  },

and also i already connect the project with the db in myApp.js:

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

mongoose.connect(process.env.MONGO_URI, { useNewUrlParser: true, useUnifiedTopology: true });

this is my env file:
image

this is my shell, the app is working well but still dont wanna pass in freecodecamp test:
“Your app is listening on port 3000” is in the shell

Is there anyone who is also stuck like this?

use console.log to see the error if you have one:

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

mongoose.connect(process.env.MONGO_URI, { useNewUrlParser: true, useUnifiedTopology: true })
  .then(() => {
    console.log('MongoDB connected!');
  })
  .catch((err) => {
    console.error('MongoDB connection error:', err);
  });

I found the error. It’s bcs I should input view URL instead of edit URL into the Freecodecamp input box.

Thanks for the answer, btw!

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.