var express = require('express');
var bodyParser = require('body-parser')
var port = process.env.PORT || 3000
var app = express()
var path = require('path');
var mongoose = require('mongoose')
var _ = require('underscore')
var fs = require('fs');
var jsonParser = bodyParser.json()
var urlencodedParser = bodyParser.urlencoded({ extended: false })
mongoose.connect('mongodb://localhost/meetdb')
app.set('views', './views/pages')
app.set('view engine', 'jade')
app.use(urlencodedParser);
app.use(express.static(path.join(__dirname, 'public')))
app.listen(port)
// user 相关
app.post('/user/signup',function (req,res){
console.log(req.params)
console.log(req.body)
})
可以获取到req.body,但是无法获取到req.params。我看网上说的是可以同时获取query和body的值。
Usually req.params to get the parameters in the path
As far as I understand,
req.params
only has parameters in parameterized paths. Do you want to get the parameters in the query string?req.params
只有在参数化的路径中的参数。你想取的是查询字符串中的参数吗?查询字符串中的参数要用
req.query
.比如
这样的请求,应该是要用
req.query.foo
和req.query.bar
来获取 foo 和 bar 的值,最终打印出如下:话说这种问题
The parameters in the query string must useconsole.log
req.query
.For example rrreee rrreee Such a request should use
rrreeereq.query.foo
andreq.query.bar
to obtain the values of foo and bar. The final printout is as follows:Speaking of this problem, the efficiency of
🎜🎜🎜🎜🎜 🎜Look how cool it is to use VSCode breakpoints to view variables. 🎜console.log
is too slow, why not use breakpoints:/user/signup Here /user/signup/:aaa you have params