I am learning nodejs and express package,during my study i get various syntax such as
var id = req.params.id;
var wine = req.body;
With my req object we are acessing body, params.id , I am not getting how they works and what result we get, please tell me about these syntax ?
An reference example where they use is :
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]);
}
});
});
}
In above example our console.log(doctor) will return {} only, what is its meaning ?
req is the request object. It's documented here: http://expressjs.com/api.html#req.params
req is an object containing information about the HTTP request that raised the event. There is a simular Question (node.js what is res and req in expressjs?), have a look at the answers there.