-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
45 lines (31 loc) · 1011 Bytes
/
server.js
File metadata and controls
45 lines (31 loc) · 1011 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
var express = require('express');
var app = express();
var bodyParser = require('body-parser');
app.use(express.static('public'));
app.use(bodyParser.urlencoded({ extended: false }));
app.use(function (req, res, next) {
console.log('Time:', Date.now());
next();
})
app.get('/', function (req, res) {
res.send('Hello World!')
});
app.get('/user/:userId', function (req, res) {
console.log(req.params.userId + '의 정보를 가져옵니다');
// TODO 실제로 DB 에서 userId 에 해당하는 사용자 정보를 가져오는 로직을 개발해야 함
var user = {
userId: 13579,
name: 'John',
email: 'yohany_AT_gmail.com',
company: 'KossLAB'
};
res.send(user);
});
app.post('/user', function (req, res) {
console.log('데이터 확인', req.body);
// TODO 실제로 DB 데이터를 저장하는 로직을 개발해야 함.
res.send({state: 'OK', data: req.body});
});
app.listen(3000, function () {
console.log('Example app listening on port 3000!')
});