-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
41 lines (31 loc) · 934 Bytes
/
Copy pathindex.js
File metadata and controls
41 lines (31 loc) · 934 Bytes
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
require('dotenv').config();
const express = require('express');
const cors = require('cors');
const morgan = require('morgan');
const helmet = require('helmet');
const path = require('path');
const logger = require('./logger');
const { SERVER_PORT } = process.env;
// ? initialize app
const app = express();
// * Set default root path
global.ROOT_PATH = path.resolve(__dirname);
// ? setup middlewares
app.use(helmet());
app.use(cors('*'));
app.use(express.json());
// * Set dev logger for better viewing response with optimization
app.use(morgan('dev'));
// * Setup express response and body parser configurations
app.use(express.json());
app.use(
express.urlencoded({
extended: true
})
);
// ? setup route handler
app.use('/api', require('./routers'));
// ? Initiate server starting
app.listen(SERVER_PORT || 4000, () => {
logger.info(`Server running on ${SERVER_PORT}`);
});