Get data from GET request in node.js parameters undefined

狂风中的少年 提交于 2019-12-11 06:26:03

问题


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:


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



来源:https://stackoverflow.com/questions/41300727/get-data-from-get-request-in-node-js-parameters-undefined

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!