loader.js
Sat Aug 28 2021 19:11:33 GMT+0000 (Coordinated Universal Time)
Saved by
@13tinydots
#javascript
import { MongoClient } from "mongodb";
import config from "./config.js";
const client = new MongoClient(config.db);
client
.connect()
.then(() => {
console.info("Connected to MongoDB");
})
.catch((err) => {
console.error("Error starting MongoDB Client");
process.exit(1);
// using "1" as exit code because it's not a graceful exit
// using "0" as exit code because it's a graceful exit
});
process.on("SIGINT", () => {
client.close().then(() => {
console.info("MongoDB connection closed");
process.exit(0);
});
});
export default client;
content_copyCOPY
Comments