Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@peekapi/sdk-node

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@peekapi/sdk-node

Node.js SDK for PeekAPI — one-line API analytics

latest
Source
npmnpm
Version
0.1.0
Version published
Weekly downloads
8
100%
Maintainers
1
Weekly downloads
 
Created
Source

PeekAPI — Node.js SDK

npm license CI

Zero-dependency Node.js SDK for PeekAPI. Add API analytics to any Node.js framework with one line of middleware.

Install

npm install @peekapi/sdk-node

Quick Start

Express

import express from "express";
import { peekapi } from "@peekapi/sdk-node";

const app = express();
app.use(peekapi({ apiKey: "ak_live_xxx" }));

app.get("/api/users", (req, res) => res.json({ users: [] }));
app.listen(3000);

Fastify

import Fastify from "fastify";
import { peekapiFastify } from "@peekapi/sdk-node";

const app = Fastify();
app.register(peekapiFastify, { apiKey: "ak_live_xxx" });

app.get("/api/users", async () => ({ users: [] }));
app.listen({ port: 3000 });

Koa

import Koa from "koa";
import { peekapiKoa } from "@peekapi/sdk-node";

const app = new Koa();
app.use(peekapiKoa({ apiKey: "ak_live_xxx" }));

app.use((ctx) => { ctx.body = { users: [] }; });
app.listen(3000);

Hapi

import Hapi from "@hapi/hapi";
import { peekapiHapi } from "@peekapi/sdk-node";

const server = Hapi.server({ port: 3000 });
await server.register({ plugin: peekapiHapi, options: { apiKey: "ak_live_xxx" } });

server.route({ method: "GET", path: "/api/users", handler: () => ({ users: [] }) });
await server.start();

NestJS

import { Module } from "@nestjs/common";
import { APP_INTERCEPTOR } from "@nestjs/core";
import { PeekApiInterceptor } from "@peekapi/sdk-node";

@Module({
  providers: [
    {
      provide: APP_INTERCEPTOR,
      useFactory: () => new PeekApiInterceptor({ apiKey: "ak_live_xxx" }),
    },
  ],
})
export class AppModule {}

Standalone Client

import { PeekApiClient } from "@peekapi/sdk-node";

const client = new PeekApiClient({ apiKey: "ak_live_xxx" });

client.track({
  method: "GET",
  path: "/api/users",
  status_code: 200,
  response_time_ms: 42,
});

// Graceful shutdown (flushes remaining events)
client.shutdown();

Configuration

OptionDefaultDescription
apiKeyrequiredYour PeekAPI key
endpointPeekAPI cloudIngestion endpoint URL
flushInterval10000Milliseconds between automatic flushes
batchSize100Events per HTTP POST (triggers flush)
maxBufferSize10000Max events held in memory
maxStorageBytes5242880Max disk fallback file size (5MB)
maxEventBytes65536Per-event size limit (64KB)
storagePathautoCustom path for JSONL persistence file
debugfalseEnable debug logging
identifyConsumerautoCustom consumer ID extraction function
tlsOptionsundefinedTLS options for https.Agent
onErrorundefinedCallback for background flush errors

How It Works

  • Middleware intercepts every request/response
  • Captures method, path, status code, response time, request/response sizes, consumer ID
  • Events are buffered in memory and flushed in batches on a timer or when batchSize is reached
  • Flushes are async and non-blocking — <1ms overhead per request
  • On network failure: exponential backoff with jitter, up to 5 retries
  • After max retries: events are persisted to a JSONL file on disk
  • On next startup: persisted events are recovered and re-sent
  • On SIGTERM/SIGINT: remaining buffer is flushed or persisted to disk

Consumer Identification

By default, consumers are identified by:

  • X-API-Key header — stored as-is
  • Authorization header — hashed with SHA-256 (stored as hash_<hex>)

Override with the identifyConsumer option to use any header or request property:

app.use(peekapi({
  apiKey: "ak_live_xxx",
  identifyConsumer: (req) => req.headers["x-tenant-id"],
}));

What Gets Tracked

FieldDescription
methodHTTP method (GET, POST, etc.)
pathRoute path (no query strings)
status_codeResponse status code
response_time_msTime to respond in ms
request_sizeRequest body size in bytes
response_sizeResponse body size in bytes
consumer_idAPI consumer identifier
timestampISO 8601 timestamp

Requirements

  • Node.js >= 18

Contributing

  • Fork & clone the repo
  • Install dependencies — npm install
  • Run tests — npm test
  • Submit a PR

License

MIT

Keywords

api

FAQs

Package last updated on 02 Mar 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts