I'm new on Node.js and Express and now I'm observing that when I change the method on my calling app the params are in req.param([name])
, req.body.[name]
or req.query
and it depends by the method.
Now my questions are two:
- Are there some differences between these three objects? (something that could explain why a different method refill a different object)
- Is there some "problems" if I create a function/module that simple check which is full and, for example, modify the req.body object so I can call this object every time to retrieve the parameters?
EDIT: After @jfriend00 's answer I would explain better my dilemma: I'm developing an api and I would create a module that could check data passed with the different methods, for now I writing something like:
if(req.method== 'PUT' || req.method=='POST')
x=req.body.x;
else
x=req.query.x;
and I would do something at the beginning like:
if(req.query!=null)
req.body=req.query;
so, after, in all my checks I will control over req.body and not the others! Do you think that it is a bad practice?