req.params으로 임의의 값을 얻을수 있다.
import express from 'express';
app.get('/:id(\\d+)', home);
const home = (req, res) => {
console.log(req.params);
return res.send(`<h1>req.params is ${req.params.id}</h1>`);
};
화면출력
req.params is 1212
콘솔출력
{ id: '1212' }
"/:~" 이렇게 해야 patams값으로 불러올수 있음
customerRouter.get('/:id([0-9a-f]{24})', profile);
Regular expression
(\\d+)
: 숫자 만 적용됨
=> aaaa 입력하면
화면출력
Cannot GET /aaaa
([0-9a-f]{24})
: 숫자 문자(a~f) 24자 만 적용됨
=> "617fa6b4b021481155905610" 입력 가능