-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
35 lines (31 loc) · 973 Bytes
/
Copy pathapp.js
File metadata and controls
35 lines (31 loc) · 973 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
35
const express = require("express");
const tasks = require("./routes/tasks");
const app = express();
const connectDb = require("./db/connect");
const notFound = require("./middleware/not-found")
const errorHandler = require("./middleware/error-handler")
require("dotenv").config();
// middleware
app.use(express.static('./public'))
app.use(express.json());
app.use("/api/v1/tasks", tasks);
app.use(notFound)
app.use(errorHandler)
const port = process.env.PORT || 3000
/*
* app.get('/api/v1/tasks') - get all the tasks
* app.post('/api/v1/tasks') - create a new task
* app.get('/api/v1/tasks/:id') - get a single task
* app.patch('/api/v1/tasks/:id') - update task
* app.delete('/api/v1/tasks/:id') - delete tasks
*/
const start = async () => {
try {
await connectDb(process.env.MONGO_URI);
console.log("Connected to DB...");
app.listen(port, () => console.log(`App is listening at port ${port}...`));
} catch (error) {
console.log(error);
}
};
start();