Bird
0
0

Which of the following is the correct signature for an Express centralized error handling middleware?

easy📝 Syntax Q12 of 15
Node.js - Error Handling Patterns
Which of the following is the correct signature for an Express centralized error handling middleware?
Afunction errorHandler(req, res, next) { ... }
Bfunction errorHandler(err, req, res, next) { ... }
Cfunction errorHandler(err, req, res) { ... }
Dfunction errorHandler(req, res) { ... }
Step-by-Step Solution
Solution:
  1. Step 1: Recall Express error middleware signature

    Express error middleware must have four parameters: error, request, response, next.
  2. Step 2: Match the correct function signature

    Only the function with (err, req, res, next) matches the required signature.
  3. Final Answer:

    function errorHandler(err, req, res, next) { ... } -> Option B
  4. Quick Check:

    Error middleware = 4 params (err, req, res, next) [OK]
Quick Trick: Error middleware always has 4 parameters [OK]
Common Mistakes:
  • Using 3 parameters instead of 4
  • Omitting the error parameter
  • Confusing normal middleware with error middleware

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Node.js Quizzes