Backend Study/Node.js

Node.js 파라미터 전달받기

gyu.ree 2022. 7. 22. 16:50

1. path Variable 
- path Variable을 통하여 userId받기 (ex. /app/users/:useId)

const userId = req.params.userId;

 

2. Query String

- 쿼리 스트링을 통하여 userId받기 (ex. /app/users?userId=3)

const userId = req.query.userId;

 

3. body

- post 혹은 patch 메소드에서 body값으로 userId 받기

const userId = req.body.nickname;

 

- 여러 값 받기

const {email, password, nickname} = req.body;

 

4. header

- 헤더로 값 받기

const headerName = req.headers["header-name"];