added DB connection verification

This commit is contained in:
ak 2023-09-03 13:38:03 -07:00
parent 4fc1e81ba3
commit 5f7a0f0a99

12
app.js
View file

@ -2,11 +2,6 @@ const createError = require("http-errors");
const express = require("express");
const path = require("path");
const mongoose = require("mongoose");
require("dotenv").config();
mongoose.connect(
`mongodb+srv://${process.env.USER}:${process.env.PASS}@odin.eftl02o.mongodb.net/?retryWrites=true&w=majority`
);
const INDEX = require("./routes/index");
const NEWMESSAGE = require("./routes/newMessage");
@ -40,4 +35,11 @@ app.use(function (err, req, res, next) {
res.render("error");
});
(async () => {
await mongoose.connect(
`mongodb+srv://${process.env.USER}:${process.env.PASS}@odin.eftl02o.mongodb.net/?retryWrites=true&w=majority`
);
console.log("Connected to database!");
})();
module.exports = app;