-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb.js
More file actions
31 lines (23 loc) · 781 Bytes
/
Copy pathdb.js
File metadata and controls
31 lines (23 loc) · 781 Bytes
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
28
29
30
const mongoose = require('mongoose');
require('dotenv').config();
//define the Mongodb connection url
//const mongoURL = 'mongodb://localhost:27017/hotels';
//const mongodb = process.env.MONGODB_URL;
const mongodb = process.env.MONGODB_URL_LOCAL;
//setup MongoDB connection
mongoose.connect(mongodb);
//get the default connection
//Mongoose maintains a default connection object representing the MongoDB connection
const db = mongoose.connection;
//define event listeners for database connection
db.on('connected', () => {
console.log('Connected to MongoDB server')
});
db.on('disconnected', () => {
console.log('MongoDB disconnected')
});
db.on('error', () => {
console.log('MongoDB connection error')
});
//export the database connection
module.exports = db;