-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathserver.js
More file actions
27 lines (20 loc) · 745 Bytes
/
server.js
File metadata and controls
27 lines (20 loc) · 745 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
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
const app = express();
const port = process.env.PORT || 5000;
if (process.env.NODE_ENV !== "test") {
app.listen(port, () => console.log(`Running on port ${port}`));
}
// 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);
module.exports = { app };