forked from bbachi/nodejs-restapi-postgresql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
39 lines (26 loc) · 914 Bytes
/
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
const express = require('express');
const bodyParser = require('body-parser');
require('dotenv').config()
const taskController = require('./controller/task.controller')
const app = express();
const port = process.env.PORT || 3000;
app.use(bodyParser.json());
app.get('/api/tasks', (req, res) => {
taskController.getTasks().then(data => res.json(data));
});
app.post('/api/task', (req, res) => {
console.log(req.body);
taskController.createTask(req.body.task).then(data => res.json(data));
});
app.put('/api/task', (req, res) => {
taskController.updateTask(req.body.task).then(data => res.json(data));
});
app.delete('/api/task/:id', (req, res) => {
taskController.deleteTask(req.params.id).then(data => res.json(data));
});
app.get('/', (req, res) => {
res.send(`<h1>API Works !!!</h1>`)
});
app.listen(port, () => {
console.log(`Server listening on the port ${port}`);
})