express獲取參數方法:javascript
1、經過req.paramsjava
app.get('/user/:id', function(req, res){ res.send('user ' + req.params.id); });
也能夠:express
app.get('/user/:id', function(request, response){ response.send('user ' + request.params.id); });
2、經過req.bodyjson
var app = require('express')(); var bodyParser = require('body-parser'); var multer = require('multer'); app.use(bodyParser.json()); // for parsing application/json app.use(bodyParser.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencoded app.use(multer()); // for parsing multipart/form-data app.post('/', function (req, res) { console.log(req.body); res.json(req.body); })
3、經過req.queryapp
// GET /search?q=tobi+ferret req.query.q // => "tobi ferret" // GET /shoes?order=desc&shoe[color]=blue&shoe[type]=converse req.query.order // => "desc" req.query.shoe.color // => "blue" req.query.shoe.type // => "converse"