A. It does not stop execution after sending 400 response
B. It uses wrong HTTP method for data submission
C. It does not parse JSON body before accessing req.body
D. It sends response twice causing server crash
Solution
Step 1: Check response flow after validation failure
After sending 400 response, the code continues and sends 'Item accepted' response, causing multiple responses.
Step 2: Identify missing control flow
There is no return or else to stop execution after sending error response.
Final Answer:
It does not stop execution after sending 400 response -> Option A
Quick Check:
Send response then stop = return [OK]
Hint: Return after res.send to stop code [OK]
Common Mistakes:
Ignoring missing return after error response
Assuming Express auto-stops after res.send
Confusing HTTP method correctness
5. You want to create an Express route that accepts a JSON body with an array of user objects, each having a required 'email' string and optional 'age' number. Which Joi schema correctly validates this request body?
hard
A. Joi.object({ users: Joi.array().required() })
B. Joi.object({ email: Joi.string().required(), age: Joi.number() }).required()
C. Joi.array().items(Joi.string().email().required())
D. Joi.array().items(Joi.object({ email: Joi.string().email().required(), age: Joi.number() }))
Solution
Step 1: Understand the data shape
The body is an array of user objects, each with required 'email' string and optional 'age' number.
Step 2: Match schema to data shape
Joi.array().items(Joi.object({ email: Joi.string().email().required(), age: Joi.number() })) defines an array of objects with the correct fields and validations.
Final Answer:
Joi.array().items(Joi.object({ email: Joi.string().email().required(), age: Joi.number() })) -> Option D
Quick Check:
Array of objects with required email = A [OK]
Hint: Use array().items(object({...})) for arrays of objects [OK]
Common Mistakes:
Using object schema instead of array for array data
Validating array of strings instead of objects
Missing required email validation
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.