forked from CodeCoachJS/node_express_starter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
29 lines (21 loc) · 833 Bytes
/
server.js
File metadata and controls
29 lines (21 loc) · 833 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
const express = require('express');
const bodyParser = require('body-parser');
const allRoutes = require('./routes');
const cors = require('cors');
const { config } = require('dotenv');
// loads environment vars from .env
config();
// start the app and listen for requests on a port
// set to port to 3001 because OS Monterey uses 5000 for the airPlay control center.
const app = express();
const port = process.env.PORT || 3001;
// we use cors library to prevent annoying cors issues
app.use(cors());
// this allows us to get req.body in json format - very important for post requests!
app.use(bodyParser.json());
// lets load all our routes and start making requests!
app.use(allRoutes);
if (process.env.NODE_ENV !== 'test') {
app.listen(port, () => console.log(`Running on port ${port}`));
}
module.exports = { app };