I am writing a big program (in size) using node js/Express.
I have multiple app.post functions and all. so, most of them need to do validation on coming Request and send a response.
So, I am created a function called Validate(); if the validation fails I will send the response to telling " please try again with information where validation Failed".
so, I created
function validate() { ...}
in the
app.post('/',function(req,res){
...
validate();
}
All the required parameters in req I am writing to a DB so I can access any where so that is not the problem now. Issue is : How do I send the "res" object. write now in validate if I try to call res. it will complain it is not defined.
so how to resolve this.
2) I tried to write the response of validate() in DB. and after that I tried to call the res: that is :
app.post('/',function(req,res){
...
validate();
res ..
}
As node is asyc this function validate response is not used by the res.
has any one come across issue like this