-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
39 lines (33 loc) · 971 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
import express from "express";
import bodyParser from "body-parser";
import cors from "cors";
import logger from './core/logger/app-logger'
import morgan from 'morgan'
import config from './core/config/config.dev'
import connectToDb from './db/connect'
// routers
import brands from './routes/brand.route'
import categories from './routes/category.route'
import products from './routes/product.route'
const port = config.serverPort;
logger.stream = {
write: function(message, encoding){
logger.info(message);
}
};
connectToDb();
const app = express();
app.use(cors());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(morgan("dev", { "stream": logger.stream }));
app.use('/brand', brands);
app.use('/category', categories);
app.use('/product', products);
//Index route
app.get('/', (req, res) => {
res.send('Invalid endpoint!');
});
app.listen(port, () => {
logger.info('server started - ', port);
});