NoNode.js · Lesson 3 of 7
HTTP Server
Node has a built-in HTTP module that can serve requests with no dependencies. Most real apps use Express on top of it, but understanding the raw module makes Express less magical.
✦ Tip
Add error handling middleware at the end of all your routes: `app.use((err, req, res, next) => { res.status(500).json({ error: err.message }) })`. Express recognizes 4-argument middleware as error handlers. Without it, unhandled errors crash the process or return HTML error pages.
Add error handling middleware at the end of all your routes: `app.use((err, req, res, next) => { res.status(500).json({ error: err.message }) })`. Express recognizes 4-argument middleware as error handlers. Without it, unhandled errors crash the process or return HTML error pages.