-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
45 lines (39 loc) · 1.19 KB
/
server.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
*************************************************
* Resource name : Startup file
* Version : 1
* Author : Baaztech
* URL : url i.e https://villa-app.herokuapp.com/
*************************************************
* Resources
* 1.server
* 2. app.js
*************************************************
*/
require('dotenv').config();
//package for mongoose driver
const mongoose = require('mongoose');
//required packages
const http = require('http');
const app = require('./app');
const connectDB = async () => {
try {
const conn = await mongoose.connect('mongodb+srv://mdali-devops:'+process.env.MONGO_ATLAS_PW+'@villa-booking-system.k5h7zrv.mongodb.net/?retryWrites=true&w=majority', {
// useMongoClient: true
useNewUrlParser: true,
useUnifiedTopology: true
});
console.log(`MongoDB Connected: ${conn.connection.host}`);
} catch (error) {
console.log(error);
process.exit(1);
}
}
const port = process.env.PORT || 3000;
const server = http.createServer(app);
//Connect to the database before listening
connectDB().then(() => {
server.listen(port, () => {
console.log("server started successfully");
});
})