-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
51 lines (36 loc) · 957 Bytes
/
server.js
File metadata and controls
51 lines (36 loc) · 957 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
require('./config/config')
const express = require('express')
const app = express();
const bodyParser = require('body-parser')
// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false }));
// parse application/json
app.use(bodyParser.json());
app.get('/usuario', function(req, res) {
res.json('Get usuario');
});
app.post('/usuario', function(req, res) {
let body = req.body;
if (body.nombre === undefined) {
res.status(400).json({
ok: false,
mensaje: 'El nombre es requerido'
});
} else {
res.json({
persona: body
});
}
});
app.put('/usuario/:id', function(req, res) {
let id = req.params.id;
res.json({
id
});
});
app.delete('/usuario/:id', function(req, res) {
res.json('delete usuario');
});
app.listen(process.env.PORT, () => {
console.log('Escuchando en puerto ', process.env.PORT);
});