What is HTTP/2 and does Node.js support it?

Why Interviewers Ask This

Senior Node.js engineers are expected to reason about architecture, performance, and edge cases. This question separates mid-level from senior candidates by testing deep system-level understanding.

Answer

HTTP/2 is the second major version of the HTTP protocol, providing significant performance improvements over HTTP/1.1: (1) Multiplexing: multiple requests/responses over a single TCP connection simultaneously (HTTP/1.1 allows only one at a time per connection, leading to head-of-line blocking); (2) Header compression (HPACK): HTTP headers are compressed, reducing overhead significantly for repeated headers; (3) Server Push: server can proactively send resources (CSS, JS) before the client requests them; (4) Binary protocol: more efficient parsing than HTTP/1.1's text protocol. Node.js has a built-in http2 module: const server = http2.createSecureServer({ key, cert }, (req, res) => { res.end("Hello HTTP/2"); }); — requires TLS. Express.js does not natively support HTTP/2 (it uses Node's http module). For HTTP/2 with Express, use spdy package or switch to Fastify (supports HTTP/2 natively). Most production deployments use Nginx or a load balancer as an HTTP/2 terminator, forwarding HTTP/1.1 to Node.js internally — simpler than enabling HTTP/2 in Node.js directly.

Common Mistake

A common mistake is memorizing definitions without understanding implications. When asked this question, go one level deeper — explain what happens when this concept is misused or ignored.