16 lines
342 B
TypeScript
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)
|
||
|
}
|
||
|
}
|