Node.js SDK
Express Middleware
Add a single error-handling middleware to your Express app to automatically capture all unhandled errors with stack traces, HTTP context, and correlation data.
Basic Setup
Register the Vigilry error middleware after all routes. Express identifies error middleware by its 4-argument signature (err, req, res, next).
Reusable Middleware Factory
Extract the middleware into a reusable factory so it can be shared across multiple Express apps in a monorepo.
Capturing Business Events
Beyond errors, instrument key business flows directly in your route handlers.
Tips
Singleton pattern
Create one Vigilry instance (e.g. in lib/vigilry.ts) and import it everywhere. Creating multiple instances is safe but wastes connections.
Fire and forget
In high-throughput handlers you can skip await on capture() calls. The SDK queues the request internally and never blocks your response.
Correlation is key
Always include user_id and order_id (or equivalent) in correlation. This enables the risk worker to group related events and detect per-user anomalies.
Error middleware order
Vigilry error middleware should come before your final error handler so it can capture the error before a 500 is sent to the client.