-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
40 lines (32 loc) · 921 Bytes
/
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 express = require('express');
const cors = require('cors');
const morgan = require('morgan');
const { dbConnection } = require('./config/db');
class Server {
constructor() {
this.app = express();
this.port = process.env.PORT || 3000;
this.dbConnection();
this.middlewares();
this.routes();
}
async dbConnection() {
await dbConnection();
}
middlewares() {
this.app.use(morgan('dev'));
this.app.use(cors());
this.app.use(express.json());
this.app.use(express.static('public'));
}
routes() {
this.app.use('/api/auth', require('./routes/auth.routes'));
this.app.use('/api/users', require('./routes/user.routes'));
}
listen() {
this.app.listen(this.port, () => {
console.log(`Server running on port ${this.port}`);
});
}
}
module.exports = Server;