Untitled

mail@pastecode.io avatar
unknown
javascript
2 years ago
516 B
2
Indexable
Never
//db.js
const mongoose = require('mongoose');
require('dotenv').config()

const urlDb = process.env.MONGO_DB

const connectDb = async () => {
    try {
        const db = await mongoose.connect(urlDb, { useNewUrlParser: true, useUnifiedTopology: true })
        const { name, host } = db.connection
        console.log(name)
        console.log(`Connected with db name: ${name} in host: ${host}`)
    } catch (error) {
        console.error('Error to connect with db', error);
    }
}

module.exports = { connectDb }