-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
41 lines (32 loc) · 981 Bytes
/
app.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
const express = require("express");
const bodyParser = require("body-parser");
const taskController = require("./controllers/TaskController");
const userController = require("./controllers/UserController");
// db instance connection
require("./config/db");
const app = express();
const port = process.env.PORT || 3301;
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
// API ENDPOINTS
app
.route("/tasks")
.get(taskController.listAllTasks)
.post(taskController.createNewTask);
app
.route("/tasks/:taskid")
.get(taskController.readTask)
.put(taskController.updateTask)
.delete(taskController.deleteTask);
app
.route("/users")
.get(userController.listAllUsers)
.post(userController.createNewUser);
app
.route("/users/:userid")
.get(userController.readUser)
.put(userController.updateUser)
.delete(userController.deleteUser);
app.listen(port, () => {
console.log(`Server running at http://localhost:${port}`);
});