Node.js SDK

Error tracking SDK for Node.js applications.

Node.js 14+ Express

Installation

npm install @hymns/alertiqo-node

Basic Setup

const Alertiqo = require('@hymns/alertiqo-node').default;

const alertiqo = new Alertiqo({
  apiKey: 'your-api-key',
  endpoint: 'https://alertiqo.io',
  environment: 'production',
  release: '1.0.0',
});

alertiqo.init();

Usage

Capture Exceptions

try {
  throw new Error('Something went wrong');
} catch (error) {
  alertiqo.captureException(error);
}

Capture Messages

alertiqo.captureMessage('User completed checkout', 'info');

Add Breadcrumbs

alertiqo.addBreadcrumb({
  message: 'User clicked button',
  category: 'user-action',
  level: 'info',
  data: { buttonId: 'submit-btn' }
});

Set User Context

alertiqo.setUser({
  id: '12345',
  email: '[email protected]',
  username: 'johndoe'
});

Set Tags

alertiqo.setTag('page', 'checkout');
alertiqo.setTags({ 
  feature: 'payments',
  version: '2.1.0'
});

Express Middleware

const express = require('express');
const Alertiqo = require('@hymns/alertiqo-node').default;
const { alertiqoMiddleware } = require('@hymns/alertiqo-node');

const app = express();

const alertiqo = new Alertiqo({
  apiKey: 'your-api-key',
  endpoint: 'https://alertiqo.io',
});

alertiqo.init();

// Your routes here
app.get('/', (req, res) => {
  res.send('Hello World');
});

// Add error middleware (after all routes)
app.use(alertiqoMiddleware(alertiqo));

app.listen(3000);

Configuration Options

const alertiqo = new Alertiqo({
  // Required
  apiKey: 'your-api-key',
  endpoint: 'https://alertiqo.io',
  
  // Optional
  environment: process.env.NODE_ENV || 'production',
  release: '1.0.0',
  tags: { app: 'myapp' },
  captureUnhandled: true,  // Auto-capture uncaught exceptions (default: true)
  
  // Filter/modify errors before sending
  beforeSend: (report) => {
    // Return null to skip sending
    return report;
  }
});

API Reference

Method Description
init() Initialize error handlers
captureException(error, additionalData?) Capture an exception
captureMessage(message, level?) Capture a message
addBreadcrumb(breadcrumb) Add a breadcrumb
setUser(user) Set user context
setTag(key, value) Set a single tag
setTags(tags) Set multiple tags

Automatic Context

The Node.js SDK automatically captures:

  • Node.js version
  • Platform and architecture
  • Hostname
  • Memory usage
  • Process information