-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
47 lines (39 loc) · 1 KB
/
index.js
File metadata and controls
47 lines (39 loc) · 1 KB
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
const express = require('express');
const morgan = require('morgan');
// config file and load env variables
const config = require('./app/config');
// main routes
const indexRoutes = require('./app/routes/index.routes');
// Not found handler
const { notFound } = require('./app/utils/middlewares/notFound');
class Server {
app;
constructor() {
this.app = express();
this.app.set('port', config.port);
}
beforeLoadRoutes() {
this.app.use(morgan('dev'));
this.app.use(express.json());
this.app.use(express.urlencoded({ extended: false }));
}
loadRoutes() {
this.app.use(indexRoutes);
}
afterLoadRoutes() {
this.app.use(notFound);
}
start() {
this.beforeLoadRoutes();
this.loadRoutes();
this.afterLoadRoutes();
this.app.listen(this.app.get('port'), this.listen());
}
listen() {
return () => {
console.log(`App Listen on port ${this.app.get('port')}`);
console.log(`App is on mode: ${config.mode_name}`);
};
}
}
new Server().start();