Bird
0
0

What happens if you try to listen on a port already in use by another Node.js HTTP server?

medium📝 component behavior Q5 of 15
Node.js - HTTP Module
What happens if you try to listen on a port already in use by another Node.js HTTP server?
AThe server throws an error and stops
BThe server silently switches to a new port
CThe server overrides the other server
DThe server automatically restarts
Step-by-Step Solution
Solution:
  1. Step 1: Understand port binding behavior

    Only one process can listen on a port at a time; trying to reuse it causes an error.
  2. Step 2: Identify Node.js reaction

    Node.js throws an error (EADDRINUSE) and the server stops unless handled.
  3. Final Answer:

    The server throws an error and stops -> Option A
  4. Quick Check:

    Port conflict = D [OK]
Quick Trick: Port conflicts cause errors, not silent switches [OK]
Common Mistakes:
  • Thinking server auto-switches ports
  • Assuming server overrides existing one
  • Believing server restarts automatically

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Node.js Quizzes