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 🙏

© 2025 – Pkg Stats / Ryan Hefner

error-logger-sendsms

v1.0.2

Published

Lightweight error logging with Discord/Slack notifications - no database required

Readme

Error Logger SendSMS

Lightweight error logging with Discord/Slack notifications - no database required.

Features

  • 🚀 Zero Database - No database setup required
  • 📢 Multi-Platform - Send to Discord and/or Slack webhooks
  • 🔒 Privacy First - Automatic sanitization of sensitive data (passwords, tokens, PII)
  • ♻️ Retry Logic - Exponential backoff with circuit breaker
  • 🌍 Environment Aware - Auto-detects development/staging/production
  • 📦 Minimal Config - Sensible defaults, works out of the box
  • Fast - <5s notification delivery, <100ms initialization
  • 🎯 TypeScript - Full type safety with TypeScript

Installation

npm install error-logger-sendsms

Quick Start

Option 1: Using Environment Variables (Recommended)

Create .env file:

# Discord configuration
DISCORD_WEBHOOK_URL=https://discord.com/api/webhooks/YOUR_WEBHOOK_ID/YOUR_TOKEN

# Or Slack configuration
SLACK_WEBHOOK_URL=https://hooks.slack.com/services/YOUR/SLACK/WEBHOOK
SLACK_CHANNEL=#errors

Use in code:

import { ErrorLogger } from 'error-logger-sendsms';

// Automatically loads configuration from environment variables
const logger = new ErrorLogger();

// Ready to use immediately!
try {
  throw new Error('Something went wrong!');
} catch (error) {
  await logger.captureException(error);
}

await logger.captureMessage('User logged in', 'info', { userId: '123' });

Option 2: Explicit Configuration

import { ErrorLogger } from 'error-logger-sendsms';

const logger = new ErrorLogger({
  discord: {
    webhookUrl: 'https://discord.com/api/webhooks/YOUR_WEBHOOK_ID/YOUR_TOKEN'
  }
});

// Capture exceptions
try {
  throw new Error('Something went wrong!');
} catch (error) {
  await logger.captureException(error);
}

// Capture messages
await logger.captureMessage('User logged in', 'info', { userId: '123' });

Environment Variables

Node.js / Backend

# Discord
DISCORD_WEBHOOK_URL=https://discord.com/api/webhooks/...
DISCORD_USERNAME=Error Bot
DISCORD_AVATAR_URL=https://example.com/avatar.png

# Slack
SLACK_WEBHOOK_URL=https://hooks.slack.com/services/...
SLACK_CHANNEL=#errors
SLACK_USERNAME=Error Monitor

# Global Settings
ERROR_LOGGER_ENABLED=true
ERROR_LOGGER_ENVIRONMENT=production

Vite / Frontend

When using Vite, use the VITE_ prefix:

# .env
VITE_DISCORD_WEBHOOK_URL=https://discord.com/api/webhooks/...
VITE_SLACK_WEBHOOK_URL=https://hooks.slack.com/services/...
VITE_ERROR_LOGGER_ENABLED=true

Next.js

# .env.local
NEXT_PUBLIC_DISCORD_WEBHOOK_URL=https://discord.com/api/webhooks/...
NEXT_PUBLIC_SLACK_WEBHOOK_URL=https://hooks.slack.com/services/...

Use in code:

const logger = new ErrorLogger({
  discord: {
    webhookUrl: process.env.NEXT_PUBLIC_DISCORD_WEBHOOK_URL
  }
});

Both Discord and Slack

const logger = new ErrorLogger({
  discord: {
    webhookUrl: 'https://discord.com/api/webhooks/...'
  },
  slack: {
    webhookUrl: 'https://hooks.slack.com/services/...'
  }
});

// Sends to BOTH platforms
await logger.captureException(new Error('Critical error'));

Configuration

Retry Policy

const logger = new ErrorLogger({
  discord: { webhookUrl: '...' },
  retry: {
    maxAttempts: 3,        // 1-5 attempts
    baseDelay: 1000,       // Initial delay (ms)
    maxDelay: 30000,       // Maximum delay (ms)
    jitter: true           // Add randomization
  }
});

Data Sanitization

const logger = new ErrorLogger({
  discord: { webhookUrl: '...' },
  sanitization: {
    enabled: true,
    customPatterns: ['creditCard', 'ssn'],
    excludeDefaults: false  // Use built-in patterns
  }
});

Default patterns automatically sanitize:

  • Passwords (password, passwd, pwd)
  • Tokens (token, bearer, jwt, apikey)
  • Secrets (secret, private_key)
  • Email addresses
  • Credit card numbers
  • Social Security Numbers

Environment Detection

// Auto-detects from NODE_ENV, import.meta.env, or window.location
const logger = new ErrorLogger({
  discord: { webhookUrl: '...' }
});

// Or set manually
const logger = new ErrorLogger({
  discord: { webhookUrl: '...' },
  environment: 'production'
});

Runtime Configuration

const logger = new ErrorLogger({
  discord: { webhookUrl: '...' }
});

// Disable temporarily
logger.configure({ enabled: false });

// Add Slack
logger.configure({
  enabled: true,
  slack: { webhookUrl: '...' }
});

// Change environment
logger.setEnvironment('staging');

API Reference

ErrorLogger

Constructor

new ErrorLogger(config?: Partial<NotificationConfig>)

Methods

captureException(error: Error | string, metadata?: Record<string, any>): Promise<void>

Capture and send an exception.

await logger.captureException(new Error('Failed'), { userId: '123' });

captureMessage(message: string, level?: 'error' | 'warning' | 'info', metadata?: Record<string, any>): Promise<void>

Capture and send a message.

await logger.captureMessage('User action', 'info', { action: 'login' });

configure(config: Partial<NotificationConfig>): void

Update configuration at runtime.

logger.configure({ enabled: false });

setEnvironment(environment: string): void

Set environment override.

logger.setEnvironment('production');

Examples

See the examples/ directory for integration examples with:

  • Basic usage
  • Advanced configuration
  • React applications
  • Express.js servers

Performance

  • Notification delivery: <5 seconds
  • Initialization: <100ms
  • Package size: <10MB
  • Throughput: 1000 notifications/minute

Constitutional Principles

This package adheres to strict development principles:

  • Reliability First: Never fails silently, implements fallbacks
  • Privacy by Design: Automatic data sanitization
  • Test-First Development: 85%+ code coverage
  • Minimal Configuration: Works with sensible defaults
  • Performance Conscious: Minimal overhead on applications

License

MIT

Contributing

Contributions welcome! Please read our contributing guidelines and submit pull requests.