我学习的NodeJS和快递包裹,我的研究过程中,我得到的各种语法如节点中的req.body是什么?
var id = req.params.id;
var wine = req.body;
随着我req
对象,我们acessing body, params.id
,我没有得到他们是如何工作的,什么结果我们得到的,请告诉我有关这些语法? 他们使用引用的例子是:
exports.addDoctor = function(req,res){
var doctor = req.body;
console.log(doctor);
db.collection('doctors',function(err,collection){
collection.insert(doctor,{safe:true},function(err,result){
if (err) {
res.send({'error':'An error is occured'});
} else {
console.log('Success: ' + JSON.stringify(result[0]));
res.send(result[0]);
}
});
});
}
在上面的例子中我们console.log(doctor)
只会返回{}
,什么是它的意义?
'{}'是一个JavaScript ['Object'](https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Object)。 –
这一切都在文档 - [req.body](http://expressjs.com/api.html#req.body)在这里,[req.params](http://expressjs.com/api.html #req.params)在这里。 –