I get information for my route, where it is contained within req
. Ex:
router.post('/', function (req, res){
});
This information I will put in my database, however, before inserting, I have to check if all the information actually came, otherwise, there will be an exception because I would try to insert information from fields that do not exist.
I'd like to know how I can validate this fields. For example, I use:
if (req.body['name']) {
console.log('Nome foi enviado com sucesso!');
}
But doing this for all sent fields makes things more difficult, I wonder if NodeJs provides some easier and more efficient way to do this.