Why does an unhandled error crash my Node.js server?
Because unhandled errors crash the Node.js process. Use a global error handler, especially in Express, to catch and handle errors gracefully so one request's error does not take down the whole server.
Verify This Answer
Cross-check this information using these trusted sources:
More FAQs in Common Mistakes When Creating a Node.js Server
Usually because you forgot to call response.end. Without end, the response never finishes and the client waits indefinitely. Always call response.end after sending the body, even if it is empty.
The request body is a readable stream. Listen to 'data' events for chunks and 'end' for completion. For JSON, concatenate chunks and JSON.parse the result. Express makes this easier with body parsing middleware.
Because another process may use that port in production. Use process.env.PORT || 3000 so the environment can set the port, which is essential for deployment platforms that assign ports dynamically.
Still have questions?
Browse all our FAQs or reach out to our support team
