Skip to main content

Installation

npm install @squasher/node

Setup

Initialize at the top of your entry file, before other imports:
src/index.ts
import { init } from "@squasher/node";

init({
  apiKey: process.env.SQUASHER_API_KEY!,
  projectId: process.env.SQUASHER_PROJECT_ID!,
  environment: process.env.NODE_ENV,
});
init() registers handlers for process.on('uncaughtException') and process.on('unhandledRejection') automatically.

Framework Integration

import express from "express";
import { captureError } from "@squasher/node";

const app = express();

app.get("/api/users", async (req, res, next) => {
  try {
    res.json(await db.getUsers());
  } catch (error) {
    next(error);
  }
});

// Add AFTER all routes
app.use(async (err: unknown, req: express.Request, res: express.Response, _next: express.NextFunction) => {
  if (err instanceof Error) {
    await captureError(err, { url: req.originalUrl, method: req.method });
  }
  res.status(500).json({ error: "Internal server error" });
});

Manual Capture

import { captureError, captureMessage } from "@squasher/node";

await captureError(new Error("Payment failed"), { orderId: "ord_123" });
await captureMessage("Worker started", "info");
await captureMessage("Queue depth exceeds 1000", "warning");

User Context & Breadcrumbs

import { getClient } from "@squasher/node";

getClient().setUser({ id: user.id, email: user.email });

getClient().addBreadcrumb({ category: "auth", message: "User logged in" });
getClient().addBreadcrumb({ category: "db", message: "SELECT * FROM orders" });
// Last 50 breadcrumbs are included in the next error

beforeSend

init({
  apiKey: process.env.SQUASHER_API_KEY!,
  projectId: process.env.SQUASHER_PROJECT_ID!,
  beforeSend: (event) => {
    if (event.request?.url?.includes("/health")) return null; // drop noise
    delete event.extra?.password; // scrub PII
    return event;
  },
});

Runtime Compatibility

RuntimeStatus
Node.js 18+Supported
Node.js 20+ LTSRecommended
BunSupported
DenoUntested (should work via npm:)
Uses standard fetch with no native dependencies.

Configuration

OptionTypeDefaultDescription
apiKeystringRequiredProject API key (sq_pk_...)
projectIdstringRequiredProject ID
endpointstringhttps://ingest.squasher.aiIngestion endpoint
environmentstringEnvironment tag
releasestringRelease version
sampleRatenumber1Sample rate 0-1
debugbooleanfalseLog to console
beforeSendfunctionFilter/modify events