-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
33 lines (27 loc) · 902 Bytes
/
app.js
File metadata and controls
33 lines (27 loc) · 902 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
31
32
33
require("dotenv").config();
const express = require("express");
const path = require("path");
const indexRouter = require("./routes/index");
const messagesRouter = require("./routes/messages");
const app = express();
const PORT = process.env.PORT || 3000;
app.set("views", path.join(__dirname, "views"));
app.set("view engine", "ejs");
app.use(express.urlencoded({ extended: true }));
app.use(express.static(path.join(__dirname, "public")));
app.use("/", indexRouter);
app.use("/messages", messagesRouter);
app.get("*", (req, res) => {
res.status(404).render("pages/error", {
title: "Not Found",
errorMessage: "404 Not Found :C",
});
});
app.use((err, req, res, next) => {
console.error(err);
res.status(500).render("pages/error", {
title: "Error",
errorMessage: "Internal Server Error",
});
});
app.listen(PORT, () => console.log(`Server running on port ${PORT}...`));