My application was running just fine and was connected to mongoDB while developing a simple node js application. But suddenly it started showing this error. Here is a snap of the console:
Here is my file providing mongoURI, and it was working just fine before the error:
module.exports = {
mongoURI:
"mongodb+srv://glorious:glorious@cluster0-to57n.mongodb.net/test?retryWrites=true&w=majority"
};
Here is my server.js file:
const express = require("express");
const mongoose = require("mongoose");
const app = express();
// DB Config
const db = require("./config/keys").mongoURI;
// Connect to MongoDB
mongoose
.connect(db)
.then(() => console.log("MongoDB Connected"))
.catch(err => console.log(err));
app.get("/", (req, res) => res.send("Hello World"));
const port = process.env.PORT || 5000;
app.listen(port, () => console.log(`Server running on port ${port}`));
And here is my package.json file:
{
"name": "devconnector",
"version": "1.0.0",
"description": "A social network for developers",
"main": "server.js",
"scripts": {
"start": "node server.js",
"server": "nodemon server.js"
},
"author": "Utkarsh Shrivastava",
"license": "ISC",
"dependencies": {
"bcryptjs": "^2.4.3",
"body-parser": "^1.19.0",
"express": "^4.17.1",
"gravatar": "^1.8.0",
"jsonwebtoken": "^8.5.1",
"mongoose": "^5.7.13",
"passport": "^0.4.0",
"passport-jwt": "^4.0.0",
"validator": "^12.1.0"
},
"devDependencies": {
"nodemon": "^2.0.1"
}
}