-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
34 lines (25 loc) · 758 Bytes
/
server.js
File metadata and controls
34 lines (25 loc) · 758 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
34
require("dotenv").config();
const express = require("express");
const fs = require("fs");
const path = require("path");
const app = express();
const routesPath = path.join(__dirname, "routes");
app.set("view engine", "ejs");
app.use(express.urlencoded({ extended: false }));
app.use(express.json());
app.use(express.static(path.join(__dirname, "public")));
try {
fs.readdirSync(routesPath).forEach((file) => {
const route = require(path.join(routesPath, file));
app.use(route.path, route.router);
});
app.all("*", (_, res) =>
res.render("pages/pageNotFound", {
title: "SpaceTime",
})
);
} catch (err) {
console.log(err);
}
const port = process.env.PORT || 5000;
app.listen(port, () => console.log(`Server started on port ${port}`));