Skip to main content
The Argus Node.js SDK integrates with Node’s process-level event system, hooking into process.on('uncaughtException') and process.on('unhandledRejection') to automatically capture every unhandled error in your server application. For Express users, an optional error-handling middleware attaches request context (HTTP method and URL) to every captured error. The SDK has zero runtime dependencies.

Installation

Initialization

1
Call init() at the top of your entry file
2
Place init() before any routes, middleware, or application logic. This guarantees that the process-level event listeners are registered before anything can throw.
3
import { init } from '@argusdev/sdk-node';

init({
  dsn: 'https://YOUR_PUBLIC_KEY@your-domain.com/YOUR_PROJECT_ID',
  environment: 'production',
  release: '1.0.0',
});

// Your application logic starts here
4
Configure InitOptions
5
init() accepts a single InitOptions object:
6
export interface InitOptions {
  /** Your project DSN (required). Format: https://PUBLIC_KEY@host/PROJECT_ID */
  dsn: string;

  /** The environment name shown in Argus (e.g. 'production', 'staging'). */
  environment?: string;

  /** Your application's release version (e.g. '1.4.2' or a git SHA). */
  release?: string;
}
7
PropertyTypeRequiredDescriptiondsnstring✅Your Argus project DSN. A malformed DSN throws loudly at startup — fix it before deploying.environmentstring—The deployment environment (e.g. 'production', 'staging'). Shown as a filter in Argus.releasestring—Your application version or release identifier. Use it to correlate errors with deploys.

Express Middleware

Add argusErrorHandler() as the last middleware in your Express application, after all your routes and before your own custom error handler. Argus captures the error with request context, then calls next(err) to pass the error along — it observes without swallowing.
Each error captured through the middleware includes the HTTP method (e.g. GET) and the full request URL from req.originalUrl, giving you immediate context in Argus about which endpoint was hit when the error occurred.
argusErrorHandler() has no dependency on Express itself — it uses structural typing and works with any framework that follows the standard four-argument Express error-handler signature (err, req, res, next).

Manual Capture

Use captureException() inside try/catch blocks when you want to handle an error gracefully and still report it to Argus.
captureException accepts any value. If you pass something that is not an Error instance, the SDK wraps it in a new Error(String(value)) before building the event.

Crash Behavior

When an uncaughtException fires, Argus sends the event to your project and then calls process.exit(1). This matches Node.js’s own recommendation: after an uncaught exception, process state is untrustworthy, and continuing to serve requests is unsafe. Do not rely on uncaughtException as a recovery mechanism — use try/catch or domain-level error handling for that.unhandledRejection events are captured and sent to Argus without exiting the process.

Non-Error Rejections

If your code rejects a promise with a plain string, number, or object instead of an Error, Argus normalizes it automatically. The value is converted to a string and wrapped in a new Error(...) before being sent, so you always see a meaningful event in Argus rather than a silent drop.

Exported API

SymbolKindDescription
initfunctionInitializes the SDK and registers process.on listeners.
captureExceptionfunctionManually captures and sends an exception to Argus.
argusErrorHandlerfunctionReturns an Express-compatible four-argument error handler middleware.
InitOptionsinterfaceTypeScript type for the init() options object.