-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
54 lines (43 loc) · 1.56 KB
/
server.js
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import "dotenv/config";
import express from "express";
import path, { dirname } from "path";
import { fileURLToPath } from "url";
import cookieParser from "cookie-parser";
const app = express();
const port = process.env.PORT || 3000;
// connect dB
import connectDB from "./config/db.js";
connectDB();
// Import the job scheduler
import { scheduleUserDeletionJob } from "./utils/cronJob.js";
scheduleUserDeletionJob();
import authRoutes from "./routes/authRoutes.js";
import profileRoutes from "./routes/profileRoutes.js";
import notesRouter from "./routes/notesRoutes.js";
import binRouter from "./routes/binRoutes.js";
import archiveRouter from "./routes/archiveRoutes.js";
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
app.set("views", path.join(__dirname, "views"));
app.set("view engine", "ejs");
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
app.use(cookieParser());
// Serve static files from the 'public' folder
app.use(express.static(path.join(__dirname, "public")));
// Use routes
app.use("/", authRoutes);
app.use("/profile", profileRoutes);
app.use("/notes", notesRouter);
app.use("/bin", binRouter);
app.use("/archive", archiveRouter);
// Handle 404 errors (not found)
app.use((req, res, next) => {
res.status(404).render("404", { message: "Page not found" });
});
// Global error handler
app.use((err, req, res, next) => {
console.error(err.stack);
res.status(500).render("error", { message: "Something went wrong!" });
});
app.listen(port, () => console.log(`Server running on port ${port}`));