-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathapp.js
More file actions
30 lines (23 loc) · 792 Bytes
/
Copy pathapp.js
File metadata and controls
30 lines (23 loc) · 792 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
const express = require("express");
const morgan = require("morgan");
const path = require("path");
const app = express();
const apiRouter = require("./api");
require("dotenv").config();
const cors = require("cors");
const PORT = process.env.PORT || 8080;
// body parser middleware
app.use(express.json());
app.use(cors()); // allow all origins
app.use(morgan("dev")); // logging middleware
app.use(express.static(path.join(__dirname, "public"))); // serve static files from public folder
app.use("/api", apiRouter); // mount api router
// error handling middleware
app.use((err, req, res, next) => {
console.error(err.stack);
res.status(500).send("Something broke!");
});
app.listen(PORT, () => {
console.log(`🚀 Server is running on port ${PORT}`);
});
module.exports = app;