Skip to main content

Node.js SDK

The official Node.js SDK for the Generator Labs API v4.0. Written in TypeScript with full type definitions included.

Packagegeneratorlabs (npm)
Minimum versionNode.js 18+
LanguageTypeScript (full type definitions included)
HTTP clientaxios
GitHubgenerator-labs/node-sdk

Installation

npm install generatorlabs

Or with Yarn:

yarn add generatorlabs

Usage

import { Client } from 'generatorlabs';

const client = new Client('your_account_sid', 'your_auth_token');

// Get a single host
const host = await client.rbl.hosts.get('host_id');

// List all hosts with automatic pagination
const hosts = await client.rbl.hosts.getAll();

// Create a certificate monitor
const monitor = await client.cert.monitors.create({
name: 'example.com',
});

CommonJS imports are also supported:

const { Client } = require('generatorlabs');

Configuration

const client = new Client('your_account_sid', 'your_auth_token', {
timeout: 45000,
maxRetries: 5,
retryBackoff: 2.0,
});
OptionDefaultDescription
timeout30000Total request timeout in milliseconds
maxRetries3Maximum number of retry attempts
retryBackoff1.0Backoff multiplier between retries

Webhook Verification

import { Webhook } from 'generatorlabs';

Webhook.verify(body, signatureHeader, secret, tolerance);

See Using Web Hooks for more details on webhook payloads and signature verification.

Error Handling

The Node.js SDK throws Exception errors that you can catch with standard try / catch:

import { Client, Exception } from 'generatorlabs';

try {
const host = await client.rbl.hosts.get('host_id');
} catch (err) {
if (err instanceof Exception) {
console.error(err.message);
}
}

Rate Limit Information

Rate limit details are available on every response:

console.log(response.rateLimitInfo.remaining);
console.log(response.rateLimitInfo.reset);

See What Are the API Rate Limits? for more information.