Mode:
Duration:
1
Coding works best on desktop or with an external keyboard.
Coding works best on desktop or with an external keyboard.
Custom error handling middleware in Express.
const express = require('express')
const app = express()
const port = 3000
app.get('/error', (req, res) => {
throw new Error('Something went wrong')
})
app.use((err, req, res, next) => {
console.error(err.message)
res.status(500).send('Server Error')
})
app.listen(port, () => {
console.log(`Server running at http://localhost:${port}`)
})Express.js is a fast, minimalist web framework for Node.js. It simplifies building web servers, RESTful APIs, and backend services, providing robust routing, middleware support, and HTTP utility methods.
Origin & Creator
Express.js was created by TJ Holowaychuk in 2010 as a lightweight and flexible web framework for Node.js.
Industrial Note
Express.js is preferred for building REST APIs, microservices, and server-side rendered applications where simplicity, speed, and middleware flexibility are crucial.