mirror of
https://github.com/BradNut/node-auth
synced 2025-09-08 17:40:17 +00:00
20 lines
No EOL
483 B
JavaScript
20 lines
No EOL
483 B
JavaScript
import mongo from 'mongodb'
|
|
|
|
const { MongoClient } = mongo
|
|
|
|
const url = process.env.MONGO_URL
|
|
|
|
export const client = new MongoClient(url, { useNetUrlParser: true })
|
|
|
|
export async function connectDb() {
|
|
try {
|
|
await client.connect()
|
|
// Confirm connection
|
|
await client.db("admin").command({ ping: 1 })
|
|
console.log("🗄️ Connected to DB Success");
|
|
} catch(e) {
|
|
console.error(e)
|
|
// If there is a problem close connection to db
|
|
await client.close()
|
|
}
|
|
} |