-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
29 lines (22 loc) · 707 Bytes
/
app.js
File metadata and controls
29 lines (22 loc) · 707 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 morgan = require("morgan");
const config = require("config");
const starsRoutes = require("./controllers");
// Set up server app
const app = express();
// Set up middleware
app.use(morgan("dev"));
// Handle routing
app.route("/api/v1/stars").get(starsRoutes.getAllStars);
app.route("/api/v1/stars/:name").get(starsRoutes.getOneStar);
// 404 errors
app.use((req, res) => {
res.status(404).send("Page not found!");
});
// Any other errors
app.use((err, req, res) => {
res.status(500).send("Server error");
});
// Run server
const port = process.env.PORT || config.get("port");
app.listen(port, () => console.log(`Server is listening on port ${port}...`));