A. Validators are not used as middleware before the route handler
B. validationResult is called incorrectly
C. Missing import of express
D. Response status code 422 is invalid
Solution
Step 1: Check how validators are applied
Validators like body('username').notEmpty() must be middleware before the route handler, not called inside it.
Step 2: Identify correct middleware usage
Validators should be passed as an array before the handler function in app.post.
Final Answer:
Validators are not used as middleware before the route handler -> Option A
Quick Check:
Validators must be middleware, not called inside handler [OK]
Hint: Validators go before handler as middleware, not inside it [OK]
Common Mistakes:
Calling validators inside route handler function
Ignoring middleware order
Assuming validationResult usage is wrong
5. You want to validate a user registration form with fields: email, password, and age. The rules are: email must be valid, password at least 8 characters, and age must be an integer between 18 and 99. Which express-validator setup correctly applies these rules and handles errors?