1. body-parser: body 데이터를 분석(parse)하여 req.body로 출력해주는 것
https://www.npmjs.com/package/body-parser
body-parser
Node.js body parsing middleware. Latest version: 1.20.0, last published: 2 days ago. Start using body-parser in your project by running `npm i body-parser`. There are 20723 other projects in the npm registry using body-parser.
www.npmjs.com
$ npm install body-parser
예시코드
var express = require('express')
var bodyParser = require('body-parser')
var app = express()
// create application/json parser
var jsonParser = bodyParser.json()
// create application/x-www-form-urlencoded parser
var urlencodedParser = bodyParser.urlencoded({ extended: false })
// POST /login gets urlencoded bodies
app.post('/login', urlencodedParser, function (req, res) {
res.send('welcome, ' + req.body.username)
})
// POST /api/users gets JSON bodies
app.post('/api/users', jsonParser, function (req, res) {
// create user in req.body
})
'Node.js' 카테고리의 다른 글
[Node.js] 프로젝트 서버 heroku에 배포하기-github 연동 (0) | 2022.06.29 |
---|---|
[Node.js] jwt에러 Error: Expected "payload" to be a plain object. (0) | 2022.04.05 |
[Node.js] Mongoose connect option is not supported (0) | 2022.04.01 |
[Node.js] mysql, sequelize 데이터베이스 세팅 (0) | 2022.03.25 |
[Node.js] 폴더 구조 정리 (0) | 2022.03.24 |