npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

klog-network-sdk

v1.0.1

Published

Network monitoring SDK for React Native and web apps

Readme

klog-network-sdk

Zero-dependency network monitoring SDK. Patches globalThis.fetch to automatically capture and ship network logs to your klog backend.

Works in React Native, web (React, Vue, plain JS), and Node.js. Supports axios via an interceptor attachment.

Installation

npm install klog-network-sdk

Quick start

import Klog from 'klog-network-sdk';

Klog.init({
  apiUrl: 'https://your-api.workers.dev',
  apiKey: 'your-api-key',
  appVersion: '1.0.0',
});

That's it. Every fetch call in your app is now captured and batched to klog.


React Native

// app/_layout.tsx  (Expo) or  index.js  (bare RN)
import Klog from 'klog-network-sdk';
import { Platform } from 'react-native';
import DeviceInfo from 'react-native-device-info'; // optional

Klog.init({
  apiUrl: 'https://your-api.workers.dev',
  apiKey: 'your-api-key',
  appVersion: DeviceInfo.getVersion(),
  device: {
    model: DeviceInfo.getModel(),
    osName: Platform.OS,
    osVersion: String(Platform.Version),
  },
});

With axios (React Native)

React Native's axios uses XMLHttpRequest under the hood, which the fetch patch doesn't see. Use attachAxios instead:

import axios from 'axios';
import Klog from 'klog-network-sdk';

Klog.init({ apiUrl: '...', apiKey: '...', appVersion: '1.0.0' });
Klog.attachAxios(axios); // attach after init

Track the current user

// After login
Klog.setUserId('user-123');

// After logout
Klog.setUserId('');

Track the current screen

// In your navigation listener
Klog.setScreenName('HomeScreen');

Web (React / Vue / plain JS)

// main.tsx
import Klog from 'klog-network-sdk';

Klog.init({
  apiUrl: 'https://your-api.workers.dev',
  apiKey: 'your-api-key',
  appVersion: import.meta.env.VITE_APP_VERSION ?? '0.0.0',
});

With axios (web)

import axios from 'axios';
import Klog from 'klog-network-sdk';

Klog.init({ apiUrl: '...', apiKey: '...', appVersion: '1.0.0' });
Klog.attachAxios(axios);

Node.js / backend

import Klog from 'klog-network-sdk';

Klog.init({
  apiUrl: 'https://your-api.workers.dev',
  apiKey: 'your-api-key',
  appVersion: process.env.npm_package_version ?? '0.0.0',
  captureResponseBody: false, // optional: skip large response bodies
});

Configuration

| Option | Type | Default | Description | |---|---|---|---| | apiUrl | string | required | klog API base URL | | apiKey | string | required | API key from the klog dashboard | | appVersion | string | required | Semantic version of your app (e.g. "1.2.3") | | batchSize | number | 10 | Flush after this many logs accumulate | | batchInterval | number | 5000 | Flush interval in ms | | captureRequestBody | boolean | true | Include request bodies in logs | | captureResponseBody | boolean | true | Include response bodies in logs | | maxBodySize | number | 10240 | Max body size in bytes before truncation | | ignoreUrls | string[] | [] | URL substrings to exclude from logging | | device | DeviceInfo | auto-detected | Device metadata attached to every log | | onError | (err: Error) => void | — | Called on internal SDK errors |

DeviceInfo

interface DeviceInfo {
  model?: string;    // e.g. "iPhone 14", "Pixel 7"
  osName?: string;   // e.g. "iOS", "Android", "web"
  osVersion?: string; // e.g. "17.2", "14"
}

API

Klog.init(config)                  // initialize (re-init destroys previous instance)
Klog.attachAxios(axiosInstance)    // attach axios interceptors
Klog.setUserId(id)                 // tag logs with a user id
Klog.setScreenName(name)           // tag logs with the current screen/route
Klog.setDevice(device)             // update device metadata
Klog.flush()                       // manually flush the queue (async)
Klog.destroy()                     // stop SDK and restore original fetch

Behaviour notes

  • Failed requests are flushed immediately — not batched — so errors appear in the dashboard within ~1 second.
  • Requests to apiUrl itself are automatically excluded to prevent infinite loops.
  • Klog.attachAxios() is safe to call before Klog.init() — the attachment is deferred until init runs.
  • Bodies larger than maxBodySize are truncated with a …[truncated N bytes] suffix.

TypeScript

All types are exported:

import type { KlogConfig, DeviceInfo, QueuedLog } from 'klog-network-sdk';