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

mailpit-ws

v1.0.1

Published

A TypeScript WebSocket client for Mailpit real-time events.

Downloads

410

Readme

mailpit-ws

Package Version Test Suite Code Coverage Documentation

A TypeScript WebSocket client for Mailpit's real-time event stream. Get instant notifications when messages are received, updated, or deleted. Works in Node.js, browser, and any modern JS runtime.

For the REST API client, see mailpit-api.

Installation

npm install mailpit-ws

mailpit-api is a peer dependency. You may need to install it separately if your package manager does not auto-install peer dependencies.

Documentation

Detailed documentation covering all available methods and type definitions.

Usage

Prerequisites: These examples require a Mailpit installation. See the Mailpit installation guide.

Listening for Events

import { MailpitEvents } from "mailpit-ws";

const events = new MailpitEvents("http://localhost:8025");

// Register listener before connecting so no events are missed
const unsubscribe = events.onEvent("new", (event) => {
  console.log("New message:", event.Data.Subject);
});

// Ensure the socket is open before triggering any action that generates events
await events.connect();

// trigger app action that sends an email...

// Stop listening
unsubscribe();

// Close the WebSocket connection
events.disconnect();

Playwright Fixture Pattern

If you are using Playwright fixtures, connect once in fixture setup and await it before any test actions run:

import { test as base } from "@playwright/test";
import { MailpitEvents } from "mailpit-ws";

type Fixtures = { events: MailpitEvents };

export const test = base.extend<Fixtures>({
  events: async ({}, use) => {
    const events = new MailpitEvents("http://localhost:8025");

    // Ensure socket is ready before any test step can trigger events
    await events.connect();

    await use(events);
    events.disconnect();
  },
});

// In tests: register listeners, then trigger actions
test("captures new message event", async ({ events }) => {
  const newEventPromise = events.waitForEvent("new");
  // trigger app action that sends an email...
  const newEvent = await newEventPromise;
  console.log(newEvent.Type);
});

Event Types

| Event | Description | | ---------- | ------------------------------------------ | | new | A new message was received | | stats | Mailbox statistics updated (total, unread) | | update | A message was updated (read status, tags) | | delete | A message was deleted | | prune | Messages were pruned | | truncate | All messages were deleted | | error | An error occurred | | * | Wildcard - receive all events |

Using with Authentication

import { MailpitEvents } from "mailpit-ws";

const events = new MailpitEvents("http://localhost:8025", {
  auth: { username: "user", password: "pass" },
});

Browser Note

Basic authentication is not supported for WebSocket connections in browsers. The native WebSocket API does not allow custom headers. This limitation does not apply to Node.js.