Node.js — Lescopr SDK

Integrate the Lescopr SDK into your Node.js application for automatic error capture, uncaught exception tracking, and real-time monitoring.

Introduction

The Lescopr Node.js SDK provides zero-configuration monitoring for any JavaScript project.

A single call to lescopr.init() hooks into uncaughtException, unhandledRejection and process.exit, then streams every error and log in real-time to your Lescopr dashboard.

The package is available on npm, has zero runtime dependencies, and works with Node.js ≥ 16.

Requirements

Before installing the Lescopr SDK, make sure your environment meets the following requirements:

  • Node.js >= 16.0.0
  • npm, yarn or pnpm (any recent version)
  • A valid LESCOPR_SDK_KEY and LESCOPR_API_KEY (available from your Lescopr dashboard)

Zero runtime dependencies — only Node.js built-ins: https, fs, path.

Installation

Install the package via your preferred package manager:

Terminal
bash
npm install lescopr
Terminal
bash
yarn add lescopr
Terminal
bash
pnpm add lescopr

Configuration

Initialise the SDK in your project directory — this detects your framework, registers the project and writes .lescopr.json:

Then call lescopr.init() at the very top of your entry point:

Store your keys in environment variables:

Available options:

  • sdkKey — Your Lescopr SDK key (required)
  • apiKey — Your Lescopr API key (required)
  • environment — development (default) or production
  • debug — Verbose logging to .lescopr.log (default: false)
  • batchSize — Logs per flush (default: 50)
  • flushInterval — ms between flushes (default: 5000)
Terminal
bash
npx lescopr init --sdk-key YOUR_SDK_KEY
index.js
javascript
const lescopr = require('lescopr');

lescopr.init({
  sdkKey:      process.env.LESCOPR_SDK_KEY,
  apiKey:      process.env.LESCOPR_API_KEY,
  environment: process.env.NODE_ENV,
});

// your application code
.env
dotenv
LESCOPR_SDK_KEY=lsk_xxxx
LESCOPR_API_KEY=lak_xxxx
LESCOPR_ENVIRONMENT=production

Usage

Once initialised, uncaughtException and unhandledRejection are captured automatically.

You can also log events and capture exceptions manually from anywhere in your code:

index.js
javascript
lescopr.log('info', 'Server started', { port: 3000 });

try {
  riskyOperation();
} catch (err) {
  lescopr.captureException(err);
  throw err;
}

Advanced

CLI commands

  • npx lescopr init --sdk-key KEY — Initialise, detect framework, write .lescopr.json
  • npx lescopr status — Show current configuration
  • npx lescopr diagnose — Node version, config, API connectivity
  • npx lescopr reset — Remove .lescopr.json and .lescopr.log

Environment variables

  • LESCOPR_SDK_KEY — SDK key (overrides .lescopr.json)
  • LESCOPR_API_KEY — API key
  • LESCOPR_ENVIRONMENT — development or production
  • LESCOPR_DEBUG=true — Verbose output to .lescopr.log
app.js
javascript
const express = require('express');
const lescopr  = require('lescopr');
const { lescoprMiddleware, lescoprErrorHandler } = require('lescopr/express');

lescopr.init({ sdkKey: process.env.LESCOPR_SDK_KEY, apiKey: process.env.LESCOPR_API_KEY });

const app = express();
app.use(lescoprMiddleware());

// ... your routes ...

app.use(lescoprErrorHandler()); // must be LAST
server.js
javascript
const fastify = require('fastify')({ logger: true });
const lescopr  = require('lescopr');

lescopr.init({ sdkKey: process.env.LESCOPR_SDK_KEY, apiKey: process.env.LESCOPR_API_KEY });

fastify.register(require('lescopr/fastify'));