Skip to content

Instantly share code, notes, and snippets.

@chicho69-cesar
Created June 20, 2023 20:33
Show Gist options
  • Save chicho69-cesar/5c6e9a4eb730ce603ca3be582625a812 to your computer and use it in GitHub Desktop.
Save chicho69-cesar/5c6e9a4eb730ce603ca3be582625a812 to your computer and use it in GitHub Desktop.
Conexion a una base de datos en MongoDB con Mongoose
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