-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
30 lines (28 loc) · 740 Bytes
/
Copy pathapp.js
File metadata and controls
30 lines (28 loc) · 740 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
const connectDB = require("./db/connection");
require("dotenv").config();
const express = require("express");
const tasks = require("./routes/task");
const notFound = require("./middlewares/not-found");
const errorHandlerMiddleware = require("./middlewares/errorHandler");
const app = express();
app.use(express.json());
app.use(
express.urlencoded({
extended: false,
})
);
app.use("/api/v1/tasks", tasks);
app.use(notFound);
app.use(errorHandlerMiddleware);
const PORT = process.env.PORT || 3000;
const start = async () => {
try {
await connectDB(process.env.MONGO_URI);
app.listen(PORT, () => {
console.log(`server listening at port ${PORT}`);
});
} catch (error) {
console.log(error);
}
};
start();