req.params는 url을 분석하여 ‘이미 예약된 값’을 받아옴.
// 서버
post.get("/:id/:name", function);
// 클라이언트
await axios({
method: "get",
url: "www.example.com/1/mj",
params: {title: "hello!"},
})
코드가 위와 같을때, 전송되는 url은 ‘www.example.com/1/mj?title=hello!’이다.
이 경우 req.params와 req.query를 출력하면 나오는 값을 각각 다음과 같다
console.log(req.params); // {id: "1", name: "mj"}
console.log(req.query); // {title: "hello"}
req.query는 url에서 ‘?’ 뒤에 입력되는 query문을 받아온 값이다.
'TIL > Node.js, express' 카테고리의 다른 글
Node.js(express) & React를 이용한 카카오 소셜 로그인 구현하기 - 2 (0) | 2022.08.20 |
---|---|
Node.js(express) & React를 이용한 카카오 소셜 로그인 구현하기 - 1 (0) | 2022.08.18 |
Node.js/Express) PM2 사용법, 코어와 쓰레드 <TIL_2022_08_05> (0) | 2022.08.05 |
서버 배포 후 카카오 로그인 KOE006 에러 <TIL_2022_08_04> (0) | 2022.08.04 |
Node.js/Express) Sequelize로 테이블 간 관계성 활용하기 <TIL_2022_07_29> (0) | 2022.07.29 |