Hi All,
I am new to working on the back end of a website and have written the below code. It runs locally but the connection isn’t made when I host the back end code on Heroku. It seems that a connection isn’t even being made to MongoDB. Perhaps someone has some insight because I am very lost.
require('dotenv').config();
const mongoose = require("mongoose");
async function dbConnect() {
// use mongoose to connect this app to our database on mongoDB using the DB_URL (connection string)
mongoose
.connect(
process.env.DB_URL,
{
// these are options to ensure that the connection is done properly
useNewUrlParser: true,
useUnifiedTopology: true
})
.then(() => {
console.log("Successfully connected to MongoDB Atlas!");
})
.catch((error) => {
console.log("Unable to connect to MongoDB Atlas!");
console.error(error);
});
}
module.exports = dbConnect;