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

sniplog

v1.0.0

Published

SnipLog SDK for error tracking - supports both Node.js/Express backend and browser frontend

Downloads

185

Readme

SnipLog SDK

Enterprise-grade error tracking SDK for Node.js/Express backends and browser frontends.

Installation

npm install sniplog-sdk

Usage

Node.js / Express Backend (Current Focus)

Basic Setup

const express = require('express');
const SnipLog = require('sniplog-sdk');

const app = express(); 

// Initialize SnipLog
const sniplog = new SnipLog({
  endpoint: 'http://localhost:3000/api/errors',
  projectKey: 'your-project-key',
  autoCaptureExceptions: true, // Auto-capture uncaught exceptions
  timeout: 5000
});

// Add request middleware (adds req.sniplog helper)
app.use(sniplog.requestMiddleware());

// Your routes here...

// Add error middleware - MUST be after all routes
app.use(sniplog.errorMiddleware());

app.listen(3000);

Configuration Options

const sniplog = new SnipLog({
  endpoint: 'http://localhost:3000/api/errors',  // SnipLog backend URL
  projectKey: 'your-api-key',                    // Project API key
  autoCaptureExceptions: true,                    // Auto-capture process errors (default: true)
  enabled: true,                                  // Enable/disable SDK (default: true)
  timeout: 5000,                                  // Request timeout in ms (default: 5000)
  discordWebhook: 'https://discord.com/api/webhooks/...'  // Optional: Discord webhook URL
});

Manual Error Capture

app.get('/api/data', async (req, res) => {
  try {
    const data = await fetchData();
    res.json(data);
  } catch (err) {
    // Capture error with context
    req.sniplog.captureError(err, {
      userId: req.user?.id,
      operation: 'fetch-data',
      endpoint: '/api/data'
    });
    
    res.status(500).json({ error: 'Failed to fetch data' });
  }
});

Capture Messages (Non-Errors)

app.post('/api/users', (req, res) => {
  req.sniplog.captureMessage('New user registration attempt', {
    level: 'info',
    email: req.body.email
  });
  
  // ... handle registration
});

Express Middleware Features

Request Middleware (sniplog.requestMiddleware())

  • Adds req.sniplog.captureError() and req.sniplog.captureMessage() helpers
  • Automatically includes request context (method, URL, IP, user-agent)

Error Middleware (sniplog.errorMiddleware())

  • Captures all errors that reach Express error handlers
  • Includes full request context
  • Must be placed AFTER all routes and middleware

Auto-Capture Features

When autoCaptureExceptions: true:

  • uncaughtException events are captured
  • unhandledRejection events are captured

Each captured error includes:

  • Error message and stack trace
  • System info (Node version, OS, hostname)
  • Process ID and session ID
  • Custom metadata you provide

Example: Complete Express App

See example-express-app.js for a full working example.

To run the example:

# Start the SnipLog backend first (in another terminal)
cd backend
npm start

# Run the example app
cd sdk
node example-express-app.js

# Test error capture
curl http://localhost:4000/test-error

Browser / Frontend (Coming Soon)

For frontend integration, include browser.js directly:

<script src="/path/to/sniplog-sdk/src/browser.js"></script>
<script>
  SnipLog.init({
    endpoint: 'http://localhost:3000/api/errors',
    projectKey: 'your-project-key'
  });
</script>

The browser SDK will automatically capture:

  • window.onerror (script errors)
  • unhandledrejection (promise rejections)
  • console.error (optional)

API Reference

Node.js SDK

new SnipLog(config)

Creates a new SnipLog instance.

Parameters:

  • config.endpoint (string): SnipLog backend URL
  • config.projectKey (string): Your project API key
  • config.autoCaptureExceptions (boolean): Auto-capture process errors (default: true)
  • config.enabled (boolean): Enable/disable SDK (default: true)
  • config.timeout (number): Request timeout in ms (default: 5000)
  • config.discordWebhook (string): Optional Discord webhook URL for real-time notifications

sniplog.captureError(error, metadata)

Manually capture an error.

Parameters:

  • error (Error): The error object
  • metadata (object): Additional context (userId, operation, etc.)

sniplog.captureMessage(message, metadata)

Capture a non-error message/event.

Parameters:

  • message (string): The message
  • metadata (object): Additional context

sniplog.requestMiddleware()

Returns Express middleware that adds req.sniplog helpers.

sniplog.errorMiddleware()

Returns Express error handling middleware. Place after all routes.


Discord Webhook Integration

SnipLog supports real-time error notifications via Discord webhooks. Errors will be sent to both the backend database AND your Discord channel.

Setup Discord Webhook

  1. Open Discord and go to your server
  2. Go to Server Settings > Integrations > Webhooks
  3. Click New Webhook or Create Webhook
  4. Copy the Webhook URL

SDK Configuration

const sniplog = new SnipLog({
  endpoint: 'http://localhost:3000/api/errors',
  projectKey: 'your-api-key',
  discordWebhook: 'https://discord.com/api/webhooks/1234567890/your-webhook-token'
});

Backend Configuration

Alternatively, configure Discord webhook in the backend (all projects will use it):

.env file:

DISCORD_WEBHOOK_URL=https://discord.com/api/webhooks/1234567890/your-webhook-token

Discord Message Format

When an error occurs, you'll receive a Discord message like:

🚨 **expressError**: Cannot read property 'id' of undefined
📅 **Time**: 10/31/2025, 3:45:12 PM
🔗 **URL**: /api/users/123
📍 **Method**: GET
💻 **Host**: production-server
👤 **User**: user-456

Error: Cannot read property 'id' of undefined at getUserProfile (/app/routes/users.js:45:20) at Layer.handle [as handle_request] at next (/app/node_modules/express/lib/router/route.js:137:13)

Features

  • ✅ Real-time notifications in Discord
  • ✅ Formatted with emojis and markdown
  • ✅ Includes error message, stack trace, and metadata
  • ✅ Truncated to fit Discord's 2000 character limit
  • ✅ Works for both SDK and backend configurations

Development

Project Structure

sdk/
├── src/
│   ├── index.js        # Auto-detects environment (Node/browser)
│   ├── node.js         # Node.js/Express SDK
│   └── browser.js      # Browser SDK (for future frontend use)
├── example-express-app.js
├── package.json
└── README.md

Testing Locally

# Link SDK locally
cd sdk
npm link

# Use in your project
cd your-express-app
npm link sniplog-sdk

Contributing

We welcome contributions! If you'd like to improve the SDK, please open an issue or submit a pull request.

For details, see our CONTRIBUTING.md guide.

Thanks for helping make SnipLog better!


License

MIT