Backend Boilerplates
javascript
Beginner
Express Async Error Handler
Centralised error middleware for Express that catches thrown errors and rejected async handlers.
javascript
// Register after all routes
const errorHandler = (err, req, res, next) => {
const status = err.status || 500;
const message = err.message || 'Internal server error';
res.status(status).json({ error: { message } });
};
module.exports = errorHandler;
Prerequisites
- express >= 4.x
Pro Tips
- → Register this middleware LAST.
- → Strip err.stack in production.
Commercial Licensing
Acquire a production access token or template license for enterprise deployment.
Module Info
- Language
- javascript
- Level
- Beginner
- Read time
- 2 min
- Published
- Jun 2024
- License
- Commercial License
Newsletter
New modules every week, directly to your inbox.
Similar Modules
Laravel Artisan Seeder Command
Artisan command to re-seed production data with a confirmation prompt.
php
·
Intermediate
CSV to PostgreSQL Bulk Loader
Stream a large CSV directly into PostgreSQL using COPY for maximum throughput.
python
·
Intermediate
Go Event Sourcing Store
Minimal append-only event store in Go backed by a Postgres table.
go
·
Advanced