Bird
0
0

Identify the error in this Node.js HTTP server code:

medium📝 Debug Q14 of 15
Node.js - HTTP Module
Identify the error in this Node.js HTTP server code:
import http from 'http';
const server = http.createServer((req, res) => {
  res.write('Hello');
  res.write('World');
  res.end();
});
server.listen(3000);
ANo error, code works fine
BCannot call res.write multiple times
CMissing res.end() call
Dres.end() should have a string argument
Step-by-Step Solution
Solution:
  1. Step 1: Review usage of res.write and res.end

    Node.js allows multiple res.write calls before res.end to send chunks.
  2. Step 2: Confirm res.end usage

    Calling res.end() without argument is valid; it ends the response.
  3. Final Answer:

    No error, code works fine -> Option A
  4. Quick Check:

    Multiple res.write calls + res.end() is valid [OK]
Quick Trick: Multiple res.write calls are allowed before res.end [OK]
Common Mistakes:
  • Thinking res.end must have argument
  • Believing multiple res.write calls cause error
  • Forgetting res.end is needed to finish response

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Node.js Quizzes