Files
back-projet-bUT3/src/helpers/databaseConnection.ts

16 lines
342 B
TypeScript
Raw Normal View History

2024-01-28 14:31:51 +01:00
import mongoose from 'mongoose'
export const databaseConnection = async () => {
const mongoUrl: string = decodeURIComponent(process.env.MONGO_URL || '')
if (mongoUrl === '') {
throw new Error('MONGO_URL has not been set')
}
try {
await mongoose.connect(mongoUrl)
} catch (err: any) {
console.error(err.message)
}
}