smart-error-handler
A production-safe and developer-friendly
Express error-handling middleware that provides:
- ✅ Clean, user-friendly error pages in production
- 🔥 Interactive stack traces in development
- 🧠 Clickable stack frames with highlighted source code
- 📦 JSON fallback for API clients
- ⚙️ Custom logging and configurable code snippets
Ideal for Express apps that want excellent developer experience without exposing sensitive details in production.
---
Features
- Interactive HTML stack trace (development only)
- Syntax-highlighted source code snippets
- Click-to-expand stack frames
- Safe minimal error page in production
- JSON response fallback for APIs
- Custom logger support
- Configurable snippet context size
---
Environment Modes
- The middleware automatically switches behavior based on:Environment Modes
---
Installation
```bash
npm install smart-error-handler
NODE_ENV=production
const express = require('express');
const { ErrorHandler, NotFoundHandler } = require('smart-error-handler');
const app = express();
// Your routes
app.get('/', (req, res) => {
throw new Error('Boom!');
});
// Register AFTER all routes
app.use(NotFoundHandler());
app.use(ErrorHandler({ logger: console.log }));
app.listen(3000, () => {
console.log('Server running on http://localhost:3000');
});