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

@traceora/express

v0.4.8

Published

Express middleware for Traceora runtime intelligence

Readme

   

Correlates matching frontend requests with Express-side events through response headers. No WebSocket or Redis service is required; configure CORS and tracing explicitly for your deployment.


📥 Installation

npm install @traceora/express

🔧 Quick Start

Two steps: add CORS headers, add the middleware.

import express from 'express';
import cors from 'cors';
import { traceora } from '@traceora/express';
import { emitTraceEvent } from '@traceora/node';

const app = express();

// 1. MUST expose the custom header so the browser can read it
app.use(cors({ exposedHeaders: ['X-Traceora-Events'] }));

// 2. Add Traceora middleware BEFORE your routes
app.use(traceora());

// 3. Emit backend events anywhere — no need to pass `req` around
app.get('/api/users', async (req, res) => {
  emitTraceEvent({
    type: 'STATE_CHANGE',
    source: 'MySQL',
    metadata: {
      query: 'SELECT * FROM users WHERE active = 1',
      durationMs: 145,
    },
  });

  res.json({ success: true });
});

app.listen(4000);

⚙️ How It Works

React Frontend                       Express Backend
──────────────                       ───────────────
1. fetch('/api/users')
   + X-Traceora-TraceId header  →  2. Middleware reads TraceId
                                       Creates AsyncLocalStorage context

                                    3. emitTraceEvent() pushes events
                                       into the current request's store
                                       (works anywhere — controllers,
                                       services, deeply nested code)

                                    4. Before sending response, middleware
                                       serializes events into:
                                       X-Traceora-Events header

5. Frontend reads header       ←  
   Merges backend events into
   the same timeline under the
   same Trace ID

6. DevTools renders backend
   events inline with frontend

🗄️ Auto-Track Database Queries

No manual emitTraceEvent() needed for database operations:

import { PrismaClient } from '@prisma/client';
import { traceoraPrismaExtension } from '@traceora/node';

const prisma = new PrismaClient().$extends(traceoraPrismaExtension());
import mongoose from 'mongoose';
import { traceoraMongoosePlugin } from '@traceora/node';

mongoose.plugin(traceoraMongoosePlugin);

📖 API Reference

traceora()

Returns the Express middleware function. Must be used after cors() and before your routes.

emitTraceEvent(event)

emitTraceEvent(event: Omit<TraceEvent, 'id' | 'traceId' | 'timestamp'>): void

Pushes an event into the current request's trace context. If called outside an active HTTP request (or the frontend didn't initiate a trace), it safely no-ops.


🔗 Related Packages

| Package | Role | |---|---| | @traceora/node | Shared backend primitives (used by this package) | | @traceora/react | Frontend counterpart that sends the Trace ID | | @traceora/core | The underlying event engine |