# Async.js — Powerful Async Utility Functions for Node.js > A utility module providing straightforward functions for working with asynchronous JavaScript. Offers collections, control flow, and utility helpers for callbacks and promises. ## Install Save as a script file and run: # Async.js — Powerful Async Utility Functions for Node.js ## Quick Use ```bash npm install async ``` ```js const async = require('async'); async.mapLimit([1, 2, 3, 4, 5], 2, async (n) => { return n * 2; }).then(results => console.log(results)); ``` ## Introduction Async.js provides around 70 utility functions for working with asynchronous JavaScript. Originally designed for Node.js callbacks, it now fully supports async/await and promises, making it useful for controlling concurrency, iterating collections in parallel, and managing complex async flows. ## What Async.js Does - Provides parallel, series, and waterfall control-flow patterns for async operations - Offers collection methods (map, filter, reduce, each) with built-in concurrency limiting - Manages task queues and priority queues for job processing with configurable parallelism - Handles retry logic, memoization, and timeout wrapping for unreliable operations - Works with callbacks, promises, and async/await interchangeably ## Architecture Overview Async.js is structured as a collection of standalone utility functions grouped into three categories: collections, control flow, and utilities. Each function accepts an async worker (callback or async function) and orchestrates its execution according to the chosen pattern. Concurrency is managed through internal counters rather than thread pools, making it lightweight and compatible with the single-threaded Node.js event loop. ## Self-Hosting & Configuration - Install via npm or yarn; no native dependencies required - Import individual functions for smaller bundles: `const mapLimit = require('async/mapLimit')` - Works in both Node.js and browser environments - No configuration files needed; concurrency limits are passed per call - Compatible with TypeScript via bundled type definitions ## Key Features - 70+ async utility functions covering most common patterns - Concurrency-limited variants (mapLimit, eachLimit, parallelLimit) prevent resource exhaustion - Queue and priority queue implementations for job processing - Automatic callback-to-promise bridging for mixed codebases - Battle-tested in production for over a decade with minimal API churn ## Comparison with Similar Tools - **Native Promise.all / Promise.allSettled** — no built-in concurrency limiting; Async.js adds throttling and richer patterns - **p-limit / p-map** — focused single-purpose modules; Async.js offers a broader utility set - **RxJS** — reactive stream-based approach; heavier and more complex for simple concurrent tasks - **Bluebird** — promise library with some concurrency helpers; Async.js provides more control-flow patterns ## FAQ **Q: Is Async.js still relevant with native async/await?** A: Yes. Native async/await does not provide concurrency limiting, queue management, or retry logic out of the box. Async.js fills those gaps. **Q: Can I import only the functions I need?** A: Yes. Each function is available as a separate submodule (e.g., `require('async/eachLimit')`) for tree-shaking and smaller bundles. **Q: Does it work in browsers?** A: Yes. Async.js runs in any JavaScript environment and can be bundled with webpack, Rollup, or other tools. **Q: How does the queue feature work?** A: `async.queue(worker, concurrency)` creates a task queue. Push tasks onto it and the worker processes up to `concurrency` tasks simultaneously. ## Sources - https://github.com/caolan/async - https://caolan.github.io/async/ --- Source: https://tokrepo.com/en/workflows/asset-3e55d35e Author: Script Depot