Skip to content

ever-co/ever-works / .agents/skills/nodejs-express-server

nodejs-express-server

Verified

Build production-ready Express.js servers with middleware, authentication, routing, and database integration. Use when creating REST APIs, managing requests/responses, implementing middleware chains, and handling server logic.

references/error-handling-middleware.md

View on GitHub
# Error Handling Middleware

## Error Handling Middleware

```javascript
class AppError extends Error {
	constructor(message, statusCode) {
		super(message);
		this.statusCode = statusCode;
		Error.captureStackTrace(this, this.constructor);
	}
}

app.use((err, req, res, next) => {
	err.statusCode = err.statusCode || 500;

	if (err.name === 'SequelizeValidationError') {
		return res.status(400).json({
			error: 'Validation failed',
			details: err.errors.map((e) => ({ field: e.path, message: e.message }))
		});
	}

	if (process.env.NODE_ENV === 'production') {
		return res.status(err.statusCode).json({
			error: err.message,
			requestId: req.id
		});
	}

	res.status(err.statusCode).json({
		error: err.message,
		stack: err.stack
	});
});

app.use((req, res) => {
	res.status(404).json({ error: 'Route not found' });
});
```
deprecation-and-migrationaddyosmani/agent-skillsManages deprecation and migration. Use when removing old systems, APIs, or features. Use when migrating users from one implementation to another. Use when migrating a database schema in production, such as renaming or dropping a column without downtime (expand/contract). Use when deciding whether to maintain or sunset existing code.Stars: 119kUpdated Claude CodeCodexVerifiedInstall
performance-optimizationaddyosmani/agent-skillsOptimizes application performance across frontend, backend, queries, and databases. Use when performance requirements exist, when you suspect performance regressions, when Core Web Vitals or load times need improvement, when N+1 query patterns need fixing, or when profiling reveals bottlenecks.Stars: 119kUpdated Claude CodeCodexVerifiedInstall
Agent Cost Reportthedotmack/claude-memBelievable agent cost report for any period, default the last 7 full days PT, not counting today. Measured tokens from Claude Code transcripts priced at OpenRouter list prices (ESTIMATED), measured provider spend when a sanctioned source exists, note-taker cost separate, Timing-style HTML/PDF plus report.json, line-items.csv, evidence.json.Stars: 118kUpdated Claude CodeCodexVerifiedInstall
Agent Cost Reportthedotmack/claude-memBelievable agent cost report for any period, default the last 7 full days PT, not counting today. Measured tokens from Claude Code transcripts priced at OpenRouter list prices (ESTIMATED), measured provider spend when a sanctioned source exists, note-taker cost separate, Timing-style HTML/PDF plus report.json, line-items.csv, evidence.json.Stars: 118kUpdated Claude CodeCodexVerifiedInstall