Created
June 20, 2023 20:33
-
-
Save chicho69-cesar/5c6e9a4eb730ce603ca3be582625a812 to your computer and use it in GitHub Desktop.
Conexion a una base de datos en MongoDB con Mongoose
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require('colors'); | |
const mongoose = require('mongoose'); | |
const dbConnection = async () => { | |
try { | |
await mongoose.connect(process.env.MONGODB_CNN, { | |
useNewUrlParser: true, | |
useUnifiedTopology: true, | |
useCreateIndex: true, | |
useFindAndModify: false | |
}); | |
console.log('Base de datos online'.green); | |
} catch (error) { | |
console.log(`${error}`.red); | |
throw new Error('Error al iniciar la base de datos'); | |
} | |
} | |
module.exports = { | |
dbConnection | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment