-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
25 lines (20 loc) · 671 Bytes
/
app.js
File metadata and controls
25 lines (20 loc) · 671 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
import express from "express";
const app = express();
import dotenv from "dotenv";
import taskRoutes from "./routes/tasks.routes.js";
import connectDb from "./db/connectDb.js";
import notFound from "./middlewares/notFound.middleware.js";
import errorHandler from "./middlewares/errorHandler.middleware.js";
dotenv.config();
const PORT = process.env.PORT;
// Connect to MongoDB
connectDb();
// Middleware
app.use(express.static("./public"));
app.use(express.json());
app.use("/api/v1/tasks", taskRoutes);
app.use(notFound); //404 Err.
app.use(errorHandler); //custom Error Handler
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT} 🛜`);
});