Problem Statement
Explain how error handling works in Node.js applications.
Explanation
Node.js uses try-catch for synchronous errors and callback or Promise rejection handlers for async code. Uncaught errors crash the process, so using centralized error middleware or process event handlers (`process.on('uncaughtException')`) ensures graceful recovery.
Code Solution
SolutionRead Only
app.use((err,req,res,next)=>{
console.error(err.stack);
res.status(500).send('Something broke!');
});