Understanding Server Response in Node.js — a practical guide to HTTP response Node.js with clear examples you can reuse in real projects.
Understanding Server Response in Node.js — 23/55 in the Node.js series. Full playlist companion: Node.js complete course on YouTube. Prefer one article? Read the complete Node.js tutorial.
Short description
Every response has a status code (200, 404, 500…), headers (content type, cache), and a body (HTML/JSON/text). Set them intentionally.
JSON response with status
res.writeHead(201, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({ ok: true, id: 12 }));