-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.js
27 lines (21 loc) · 845 Bytes
/
db.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
const mongoose = require('mongoose');
require('dotenv').config()
const URI = `mongodb+srv://fogbonda017:${process.env.URIPASS}@studentcluster.75dnuzz.mongodb.net/uniport_csc_database`
const dbConnect = async () => {
try{
const option ={
useUnifiedTopology: true,
}
mongoose.connect(URI, option);
const db = mongoose.connection;
// db.on('error', console.error.bind(console, 'Connection error'));
db.once('open', () => {
console.log('Connected to the database successfully:');
})
// res.status(200).send('Connected successfully')
} catch (error) {
console.log(`Error connecting to the database: ${error}`);
// res.status(500).json({ error: `error connecting to the database` })
}
}
module.exports = dbConnect