node.js中间件 body-parser

//第一步

var express = require('express')
var bodyParser = require('body-parser')
var app = express()

//第二步

app.use(bodyParser.urlencoded({ extended: false })) // parse application/x-www-form-urlencoded 
app.use(bodyParser.json())// parse application/json 

//第三步(路由)

app.post('/profile', function(req, res, next) {
    console.log(req.body);
    res.json(req.body);
});

你可能感兴趣的:(node.js中间件 body-parser)