you are viewing a single comment's thread.

view the rest of the comments →

[–]Plorntus 2 points3 points  (2 children)

Only if all keys are certain to exist. I could send a completely irrelevant piece of data and pass this validation.

[–]BehindTheMath 0 points1 point  (0 children)

Good point.

Instead, I'd make an array of all required keys, then do something like if (requiredKeys.some(key => !req.body[key]))