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

client.ingest

v1.0.0

Published

JavaScript client for sending logs to service.ingest via Socket.IO

Readme

client.ingest

A JavaScript/TypeScript client for sending logs to service.ingest via Socket.IO. Works in both browser (React) and Node.js environments.

Installation

npm install client.ingest socket.io-client

Quick Start

import { IngestClient } from 'client.ingest';

// Create a client instance
const client = new IngestClient({
  url: 'http://localhost:3000'
});

// Send logs
await client.info('Application started');
await client.error('Something went wrong', { errorCode: 500 });

Usage

Basic Usage

import { IngestClient } from 'client.ingest';

const client = new IngestClient({
  url: 'http://localhost:3000'
});

// Wait for connection
await client.connect();

// Send different log levels
await client.debug('Debug message');
await client.info('Info message');
await client.warn('Warning message');
await client.error('Error message');
await client.fatal('Fatal message');

// With metadata
await client.info('User logged in', {
  userId: '123',
  email: '[email protected]'
});

React Usage

import { useEffect, useRef } from 'react';
import { IngestClient } from 'client.ingest';

function App() {
  const clientRef = useRef<IngestClient | null>(null);

  useEffect(() => {
    // Initialize client
    const client = new IngestClient({
      url: 'http://localhost:3000'
    });

    clientRef.current = client;

    // Set up event handlers
    client.on('connect', () => {
      console.log('Connected to log server');
    });

    client.on('disconnect', (reason) => {
      console.log('Disconnected:', reason);
    });

    client.on('error', (error) => {
      console.error('Connection error:', error);
    });

    // Clean up on unmount
    return () => {
      client.destroy();
    };
  }, []);

  const handleClick = async () => {
    if (clientRef.current?.connected) {
      await clientRef.current.info('Button clicked', {
        timestamp: Date.now()
      });
    }
  };

  return <button onClick={handleClick}>Click me</button>;
}

React Hook Example

import { useEffect, useState, useCallback, useRef } from 'react';
import { IngestClient, LogLevel, LogResult } from 'client.ingest';

export function useIngestLogger(url: string) {
  const clientRef = useRef<IngestClient | null>(null);
  const [connected, setConnected] = useState(false);

  useEffect(() => {
    const client = new IngestClient({ url });
    clientRef.current = client;

    client.on('connect', () => setConnected(true));
    client.on('disconnect', () => setConnected(false));

    return () => {
      client.destroy();
    };
  }, [url]);

  const log = useCallback(
    async (level: LogLevel, message: string, meta?: Record<string, any>) => {
      if (clientRef.current?.connected) {
        return clientRef.current.log(level, message, meta);
      }
      return null;
    },
    []
  );

  return {
    connected,
    log,
    debug: (msg: string, meta?: Record<string, any>) => log('debug', msg, meta),
    info: (msg: string, meta?: Record<string, any>) => log('info', msg, meta),
    warn: (msg: string, meta?: Record<string, any>) => log('warn', msg, meta),
    error: (msg: string, meta?: Record<string, any>) => log('error', msg, meta),
    fatal: (msg: string, meta?: Record<string, any>) => log('fatal', msg, meta),
  };
}

// Usage:
// const logger = useIngestLogger('http://localhost:3000');
// await logger.info('Something happened');

Node.js Usage

import { IngestClient } from 'client.ingest';

const client = new IngestClient({
  url: 'http://localhost:3000',
  reconnection: true,
  reconnectionAttempts: 10
});

// Set a default source for all logs
client.setSource('my-backend-service');

// Connect and send logs
await client.connect();

await client.info('Server started', { port: 3001 });

// Handle errors
client.on('error', (err) => {
  console.error('Logger error:', err);
});

Batch Logging

await client.batch([
  { level: 'info', message: 'Step 1 completed' },
  { level: 'info', message: 'Step 2 completed' },
  { level: 'info', message: 'Step 3 completed' }
]);

Configuration Options

interface IngestClientOptions {
  /** The URL of the service.ingest server (required) */
  url: string;
  
  /** Auto-connect on instantiation (default: true) */
  autoConnect?: boolean;
  
  /** Enable reconnection (default: true) */
  reconnection?: boolean;
  
  /** Max reconnection attempts (default: Infinity) */
  reconnectionAttempts?: number;
  
  /** Delay between reconnection attempts in ms (default: 1000) */
  reconnectionDelay?: number;
  
  /** Max delay between reconnection attempts in ms (default: 5000) */
  reconnectionDelayMax?: number;
  
  /** Connection timeout in ms (default: 20000) */
  timeout?: number;
  
  /** Authentication data to send with connection */
  auth?: Record<string, any>;
}

API Reference

Methods

| Method | Description | |--------|-------------| | connect() | Connect to the server (returns Promise) | | disconnect() | Disconnect from the server | | destroy() | Disconnect and clean up all resources | | log(level, message, meta?) | Send a log with specified level | | debug(message, meta?) | Send a debug log | | info(message, meta?) | Send an info log | | warn(message, meta?) | Send a warning log | | error(message, meta?) | Send an error log | | fatal(message, meta?) | Send a fatal log | | batch(entries) | Send multiple log entries | | sendLogEntry(entry) | Send a complete LogEntry object | | setSource(source) | Set default source for all logs | | setRequestTimeout(ms) | Set timeout for requests | | on(event, listener) | Add event listener | | off(event, listener?) | Remove event listener | | once(event, listener) | Add one-time event listener | | getSocket() | Get underlying Socket.IO socket |

Properties

| Property | Description | |----------|-------------| | connected | Boolean indicating connection status | | id | Socket ID (undefined if not connected) |

Events

| Event | Description | |-------|-------------| | connect | Fired when connected to server | | disconnect | Fired when disconnected (with reason) | | error | Fired on connection error | | reconnect | Fired on successful reconnection | | reconnect_attempt | Fired on each reconnection attempt | | reconnect_error | Fired on reconnection error | | reconnect_failed | Fired when all reconnection attempts fail |

TypeScript Support

The package includes full TypeScript definitions. All types are exported:

import type {
  IngestClientOptions,
  IngestClientEvents,
  LogLevel,
  LogEntry,
  LogResult,
  JsonRpcRequest,
  JsonRpcResponse,
  JsonRpcError
} from 'client.ingest';

License

ISC