express middleware body parser code example
Example 1: body-parser npm
$ npm install body-parser
Example 2: body-parser doc
var express = require('express')
var bodyParser = require('body-parser')
var app = express()
var jsonParser = bodyParser.json()
var urlencodedParser = bodyParser.urlencoded({ extended: false })
app.post('/login', urlencodedParser, function (req, res) {
res.send('welcome, ' + req.body.username)
})
app.post('/api/users', jsonParser, function (req, res) {
})
Example 3: express json body
$ npm install body-parser
Example 4: express json body
var bodyParser = require('body-parser')