Files
back-projet-bUT3/src/helpers/databaseConnection.ts
Félix Legrelle 341889b6f7 🎉 Start project but-3
2024-03-07 11:45:33 +01:00

16 lines
342 B
TypeScript

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)
}
}