-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
45 lines (33 loc) · 891 Bytes
/
index.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
42
43
44
45
const express = require('express');
const db = require('./db.js')
const bodyParser = require('body-parser');
const app = express();
app.use(bodyParser.urlencoded())
const userDB = db.createUserDB()
app.set('view engine', 'ejs');
app.get('/', function (request, response) {
response.render('index', {
users: userDB.getUsers()
})
});
app.get('/tambah', function (request, response) {
response.render('add')
});
app.post('/tambah', function (request, response) {
const name = request.body.name;
const user = {
id: Math.random().toString(),
name: name
}
console.log(user)
userDB.addUser(user)
response.redirect('/')
})
app.delete('/users/:id', function (request, response) {
const userId = request.params.id
userDB.removeUser(userId)
response.json({
'message': "Berhasil hapus"
})
})
app.listen(4000)