使用express获取参数 Posted on 2018-02-23 Edited on 2021-04-26 In node 123456789101112131415161718192021222324252627const express = require('express')const bodyParser = require('body-parser')const app = express()//支持不同的请求体app.use(bodyParser.urlencoded({ extended: false })) //application/x-www-form-urlencoded//app.use(bodyParser.json()) //如果需要发送JSON数据 application/json//获取参数 query http://localhost:3333/?a=1app.get('/', (req, res) => { res.send('this is homepage') console.log(req.query) //{a:1}})//获取参数 params http://localhost:3000/profile/123/user/weibinapp.get('/profile/:id/user/:name', function (req, res) { res.send(`your id is ${req.params.id},yourname is ${req.params.name}`) //your id is 123,yourname is weibin})//使用bodyParser 获取post的参数,参数挂到了req.body上面 使用postman测试app.post('/', (req, res) => { console.dir(req.body)})app.listen(4000)