Express.js Advanced

Essential Git commands for everyday development — clone, commit, push, pull, and branch management.

Last Updated: May 2, 2026

Advanced Express.js patterns: middleware chains, error handling, async route wrappers, rate limiting, helmet security, and production deployment.

Middleware Patterns

PatternUsage
Application-levelapp.use(logger('dev'))
Router-levelrouter.use(authMiddleware)
Error-handlingapp.use((err, req, res, next) => { ... })
Built-inexpress.json(), express.static()

Error Handling

express-async-errors
Auto-catches async errors and passes to error handler.
Custom error classes
Extend Error with statusCode for structured error responses.

Security with Helmet

MiddlewareProtection
helmet()Sets 11 security headers
helmet.contentSecurityPolicy()Control script/style sources
helmet.frameguard()Prevent clickjacking

Production Deployment

StrategyDetails
Cluster modecluster.fork() — one per CPU core
PM2Auto-restart, log management
Graceful shutdownListen for SIGTERM, drain connections
Pro Tip: Use express-async-errors as a one-line safety net for async route handlers.