javascript - How to get path variable in express(node.js) -


i trying value of path variable "userid" using req.params getting undefined, if 1 can guide me in problem ll thankful him. have place code below. have go through example examples doing in way don't know going wrong code.
thank you,

parent router controller

app.use("/user/:userid/group",groupcontroller); 

action in controller

router.post("/", function (req, res, next) {      var group = new group(req.body);      console.log(req.params);      group.userid = req.params.userid;      group.save(new datacallbacks(req, res, next, "group").insert()); }); 

i think wrong route, can't route /user/:userid/group , post / doesn't make sense. mean useridparam, should post /user/:userid/group:

route file route.js:

var ctrl = require('controller.js');  app.route('/user/:userid/group').post(ctrl.doit); 

controller file controller.js:

exports.doit = function(req, res, netx) {     var group = new group(req.body);      console.log(req.params);      group.userid = req.params.userid;      group.save(new datacallbacks(req, res, next, "group").insert()); }); 

Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -