什么是节点中的请求?
我学习nodejs和expression包,在我学习期间,我得到各种语法,如
var id = req.params.id; var wine = req.body;
有了我的req
对象,我们正在获取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)
将只返回{}
,它的含义是什么?
req
是请求对象。 这里logging: http : //expressjs.com/api.html#req.params
req是一个包含引发事件的HTTP请求信息的对象。 有一个类似的问题( node.js expressjs中的res和req是什么? ),看看那里的答案。