const express = require('express');
const app = express();
const port = 3000;
app.get('/', (req, res) => {
res.send('Hello world!');
});
app.get('/sound/:name', (req, res) => {
const q = req.params;
if (q.name === 'dog')
res.json({ 'sound': 'Bark!' });
else if (q.name === 'cat')
res.json({ 'sound': 'Meow!' });
else
res.json({ 'sound': 'Unknown' });
});
app.listen(port);
app.<METHOD>()
를 통해 특정 메소드 요청에 대한 응답을 보냄
res.send() 또는 res.json()을 통해 응답
URI 속 :<VARIABLE>
을 통해 파라미터를 받을 수 있음 → req.params.<VARIABLE>
결과
또는
Reference