Get data from GET request in node.js parameters un

2019-07-29 10:06发布

I am trying to get parameters from get request in Node.js through Angular.JS but getting undefined in output

http://localhost:3000/admin/dashboard?id=582c5211c8a8e06c0849a238

My CRUD is

"dashboard":{
     schema:DashboardSchema,
     custom:[{
         type:"after",
         request: "get",
         controller: dashboardController.dashboard
     }]
}

My Node.js code is

dashboard: function(req,res){
     console.log("here");
     console.log(req.params);
     console.log(req.params.id);
     return res.status(200).send({"data":"123"});
});

The console window shows like this

GET /admin/dashboard?id=582c5211c8a8e06c0849a238 200 153.463 ms - 14 In decode data { id: '582c5211c8a8e06c0849a238' } here { id: undefined } undefined

Please help !

1条回答
对你真心纯属浪费
2楼-- · 2019-07-29 10:48

http://localhost:3000/admin/dashboard?id=582c5211c8a8e06c0849a238

Here as you are passing in query so try req.query.id

If you are passing the parameters as http://localhost:3000/admin/dashboard/582c5211c8a8e06c0849a238 then you can use req.params.id

查看更多
登录 后发表回答