var mongoose = require("mongoose");

function connectDB() {
  var mongoURI = process.env.MONGO_URI || "mongodb://127.0.0.1:27017/SCMS";

  return mongoose.connect(mongoURI)
    .then(function () {
    console.log("MongoDB connected successfully to SCMS database");
    })
    .catch(function (error) {
      console.error("MongoDB connection failed:", error.message);
      process.exit(1);
    });
}

module.exports = connectDB;
