-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
24 lines (17 loc) · 965 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
const express = require('express'); //import express
const bodyParser = require('body-parser'); //body parser module
const errorhandler = require('errorhandler'); //errorhandle module
const cors = require('cors'); //cross orgin resource sharing
const morgan = require('morgan'); //morgan logger module
const apiRouter = require('./api/api'); //import api router from api directory
const app = express(); //create express app
const PORT = process.env.PORT || 4000; //create port 4000 (where front-end will make requests)
app.use(bodyParser.json());
app.use(morgan('dev'));
app.use(cors());
app.use('/api', apiRouter); //all routes that have endpoint /api will be sent to apiRouter
app.use(errorhandler());
app.listen(PORT, () => {
console.log(`Listing on PORT ${PORT}`); //listen on PORT 4000
})
module.exports = app; //export express app