1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
| // index.js
const express = require('express');
const app = express();
const PORT = 4000;
app.get('/', (req, res) => {
/*
- req(request), res(response)는 express 메소드에서 제공하는 Objects arguments.
- req에는 누가 페이지를 요청했는가, 어떤 종류의 데이터가 페이지로 전송됐는가 등의 정보가 담긴다.
- 만약 response가 없으면 무한 로딩.
*/
res.send('Hello World!!');
});
app.get('/other', (req, res) => {
// get method의 첫번째 인자는 '라우트 경로'
// `http://localhost:${PORT}/other` 에서 결과 확인 가능
res.send('This is other page!');
});
app.listen(PORT, (req, res) => {
console.log(`Listening on: http://localhost:${PORT}`);
});
|