-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathserver.js
55 lines (42 loc) · 1.17 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
46
47
48
49
50
51
52
53
54
55
/**
* Real Time chatting app
* @author Shashank Tiwari
*/
'use strict';
const express = require("express");
const http = require('http');
const socketio = require('socket.io');
const bodyParser = require('body-parser');
const socketEvents = require('./utils/socket');
const routes = require('./utils/routes');
const config = require('./utils/config');
class Server{
constructor(){
this.port = process.env.PORT || 3000;
this.host = `localhost`;
this.app = express();
this.http = http.Server(this.app);
this.socket = socketio(this.http);
}
appConfig(){
this.app.use(
bodyParser.json()
);
new config(this.app);
}
/* Including app Routes starts*/
includeRoutes(){
new routes(this.app).routesConfig();
new socketEvents(this.socket).socketConfig();
}
/* Including app Routes ends*/
appExecute(){
this.appConfig();
this.includeRoutes();
this.http.listen(this.port, this.host, () => {
console.log(`Listening on http://${this.host}:${this.port}`);
});
}
}
const app = new Server();
app.appExecute();