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

busboy-async

v0.1.1

Published

Busboy Async is an async generator-ized busboy.

Readme

Busboy Async

Busboy Async is an async generator-ized busboy.

Why I Created This?

busboy(Github) is a library for parsing multipart/form-data requests in Node.js. Unlike other parsing libraries, it doesn't save to temporary files and then pass file paths or handles. Instead, it emits events with streams that are ready to be read directly. This approach has advantages: it avoids creating temporary files and doesn't load large amounts of data into memory all at once. Consequently, it eliminates the need for server access to the file system and doesn't require significant memory.

However, busboy is implemented by receiving a NodeJS.ReadableStream and emitting events via an EventEmitter interface. When file events are emitted, a NodeJS.ReadableStream interface is exposed, and library users must either process or resume this stream. If asynchronous functions are used within these event callbacks, the order of event processing isn't guaranteed. This can make business logic difficult to write and prone to errors. To address this, I created busboy-async.

Below is an example of using the original busboy. It reads files named image and document, uploads them to file storage, and updates the database. The order of each step is not guaranteed.

const bb = busboy();
bb.on("file", (name, stream, info) => {
  if (name === "image") {
    uploadImage(stream, (error) => {
      if (error) {
        // Image upload failed.
      } else {
        updateDb((error) => {
          if (error) {
            // DB update failed.
            deleteImage();
          } else {
            // DB update successful.
          }
        });
      }
    });
  } else if (name === "document") {
    uploadDocument(stream)
      .then(() => {
        updateDb()
          .then(() => {
            // DB update successful.
          })
          .catch((error) => {
            // DB update failed.
            deleteDocument();
          });
      })
      .catch((error) => {
        // Document upload failed.
      });
  } else {
    stream.resume();
  }
});

Below is an example of using busboy-async.

const bb = busboy();
try {
  for await (const event of bb) {
    const { type } = event;
    if (type === "file") {
      const { name, stream } = event;
      if (name === "image") {
        await uploadImage(stream);
        try {
          await updateDb();
        } catch (error) {
          await deleteImage();
          // Additionally, an exception can be thrown to prevent starting other file processing.
        }
      } else if (name === "document") {
        await uploadDocument(stream);
        try {
          await updateDb();
        } catch (error) {
          await deleteDocument();
          // Additionally, an exception can be thrown to prevent starting other file processing.
        }
      } else {
        stream.resume();
      }
    }
  }
} catch (error) {
  // Error handling
}

As shown above, because it's implemented using an AsyncGenerator, you can use the for await loop and guarantee the order of each processing step by using await. As in the example above, you can fully process one file at a time before moving on to the next.