-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
40 lines (30 loc) · 1.04 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
const http = require('http');
const mongoose = require('mongoose');
const dotenv = require('dotenv');
//////////////////////////////////////////////
//// ENVIROMENT CONFIGURATION ////
//////////////////////////////////////////////
const app = require('./app');
dotenv.config({ path: './config.env' });
const server = http.createServer(app);
//////////////////////////////////////////////
//// DATABASE CONFIGURATION ////
//////////////////////////////////////////////
const PORT = process.env.PORT || 2300;
const DB = process.env.DATABASE.replace('<PASSWORD>', process.env.DATABASE_PASSWORD);
async function connectDB() {
try {
await mongoose.connect(DB);
console.log('Database connected successfully!');
} catch(err) {
console.log(err.message)
}
}
connectDB();
//////////////////////////////////////////////
//// SERVER CONFIGURATION ////
//////////////////////////////////////////////
server.listen(PORT, '0.0.0.0', function() {
console.log(`Server running on port ${PORT}...`);
});
module.exports = server;