I have an Express Mongoose app that used to connect to MongoDB Atlas without any problem whatsoever.
It is hosted on Repl.it
But when I checked today, it is not working.
MongooseError: The `uri` parameter to `openUri()` must be a string, got "undefined". Make sure the first parameter to `mongoose.connect()` or `mongoose.createConnection()` is a string.
Nothing has changed from last time, 21 days ago.
The packages are all the latest version.
Here is the code.
require('dotenv').config();
const express = require('express');
const cors = require('cors');
const db = require("mongodb")
const mongoose = require('mongoose')
const bodyParser = require('body-parser')
const port = process.env.PORT || 3000;
const uri = process.env.MONGO_URI;
mongoose.connect(uri, {
useNewUrlParser:true,
useUnifiedTopology:true,
serverSelectionTimeoutMS:6000
})
const connection = mongoose.connection;
connection.on('error', console.error.bind(console, 'connection error'));
connection.once('open', () => {
console.log("Connected successfully")
});
app.listen(port, () => {
console.log(`Server is running on port : ${port}`);
})
What could be the issue?
Any idea would be highly appreciated.
Thank you.