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

async-event-pipeline

v2025.9.8

Published

A lightweight, zero-dependency package for defining a series of sequential async tasks (like filters or middleware) that pass data between them.

Readme

Async Event Pipeline

A lightweight, zero-dependency package that lets you define and execute a series of asynchronous tasks sequentially, passing data between them. It's perfect for processing requests, building data transformation pipelines, or managing job queues where order and async operations are critical.

Inspired by middleware frameworks like Express.js, Async Event Pipeline brings a similar, powerful pattern to any JavaScript/Node.js application.

Key Features

  • Sequential Execution: Tasks run one after another, ensuring a predictable order of operations.

  • Asynchronous Support: Built for async/await, allowing tasks to perform I/O operations (e.g., database queries, API calls) without blocking.

  • Data Propagation: Data is passed through the pipeline, allowing each task to inspect or modify it.

  • Error Handling: A robust next(err) pattern allows any task to halt the pipeline and propagate an error.

  • Zero Dependencies: Lightweight and easy to integrate into any project.

  • Modern Syntax: Written in ES2015+ with a clean, chainable API.

Use Cases

  • API Middleware Chains: Validate, authenticate, and process incoming HTTP requests before they hit your controller.

  • Data Validation & Transformation: Create multi-step pipelines to clean, validate, and reshape data from various sources.

  • Job Queues: Process background jobs in a specific sequence, such as sending emails, generating reports, or processing images.

  • ETL Processes: Build simple Extract, Transform, Load (ETL) workflows in a structured manner.

Installation

npm install async-event-pipeline

How It Works

The pipeline manages a queue of "tasks." When you call .execute(initialData), it passes the data to the first task.

Each task is an async function that receives two arguments:

  1. data: The data payload from the previous task.

  2. next: A callback function to pass control to the next task.

  • To continue to the next task, call next(null, modifiedData).

  • To stop the pipeline and report an error, call next(new Error('...')).

API Reference

new AsyncEventPipeline()

Creates a new pipeline instance.

.add(task)

Adds a task to the pipeline.

  • task(data, next): The function to be executed.

    • data: The data passed from the previous task.

    • next(error, newData): The callback to continue or stop the pipeline.

      • error (optional): An Error object to stop the pipeline.

      • newData (optional): The data to pass to the next task. If omitted, the original data is passed through.

Returns the AsyncEventPipeline instance for easy chaining.

.execute(initialData)

Starts the execution of the pipeline.

  • initialData: The initial data to be passed to the first task.

Returns a Promise which:

  • Resolves with the final data after the last task completes.

  • Rejects if any task calls next(error) or throws an exception.

.exec(initialData)

Alias of `execute(initialData)`

.use(task)

Alias of `add(task)`

Example: API Request Pipeline

Here's how you can simulate an API middleware chain.

// nodejs
const AsyncEventPipeline = require('async-event-pipeline');

// OR

// for browser (UMD) - add in meta
// <script src="https://cdn.jsdelivr.net/npm/async-event-pipeline/dist/async-event-pipeline.umd.js"></script>


const pipeline = new AsyncEventPipeline();

const request = {
    headers: { 'authorization': 'Bearer valid-token' },
    body: { userId: 123, content: 'Hello World' }
};

// 1. Validation Middleware
pipeline.add(async (req, next) => {
    console.log('Step 1: Validating...');
    if (!req.body || !req.body.userId) {
        return next(new Error('Validation Error: userId is missing.'));
    }
    console.log('Validation successful.');
    next(null, req); // Pass data to the next task
});

// 2. Authentication Middleware
pipeline.add(async (req, next) => {
    console.log('Step 2: Authenticating...');
    if (req.headers['authorization'] !== 'Bearer valid-token') {
        return next(new Error('Authentication Error: Invalid token.'));
    }
    req.user = { id: 123, name: 'John Doe' };
    console.log('Authentication successful.');
    next(null, req);
});

// 3. Final Processing
pipeline.add(async (req, next) => {
    console.log('Step 3: Processing...');
    req.processedData = `Content "${req.body.content}" was posted by ${req.user.name}.`;
    next(null, req);
});

// Execute the pipeline
pipeline.execute(request)
    .then(finalResult => {
        console.log('\n✅ Pipeline executed successfully!');
        console.log('Final Result:', JSON.stringify(finalResult, null, 2));
    })
    .catch(error => {
        console.error('\n❌ Pipeline execution failed:', error.message);
    });

Contributing

This is an open-source project. Contributions are welcome! Please see the CONTRIBUTING.md file for guidelines.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Changelog

Please see the CONTRIBUTING.md file.

Author

This packages codes was created by Mamedul Islam and open for contribute.

As a passionate web developer with experience in creating interactive and user-friendly web components. Currently available for freelance projects or full-time opportunities.

Helping businesses grow their online presence with custom web solutions. Specializing in WordPress, WooCommerce, and Shopify. Building modern, responsive, and high-performance scalable websites with custom made plugins, codes, customizations.

Keywords

async, await, promise, pipeline, middleware, chain, queue, task, job, filter, sequential, flow, control, validation, transformation