autocannon

raw JSON →
8.0.0 verified Sat Apr 25 auth: no javascript

An HTTP/1.1 benchmarking tool for Node.js, designed to be fast and easy to use. Current stable version is 8.0.0, released in late 2021. It supports HTTP pipelining, HTTPS, and can produce more load than wrk or wrk2. It offers both a command-line interface and a programmatic API, with features like warm-up, worker threads, HAR file replay, and custom request bodies. The project is actively maintained by the Node.js community.

error Error [ERR_REQUIRE_ESM]: require() of ES Module /path/to/autocannon/index.js from /path/to/your.js not supported.
cause Using require() to import autocannon v8 which is ESM-only.
fix
Replace require('autocannon') with import autocannon from 'autocannon' or use dynamic import().
error autocannon is not a function
cause Importing autocannon incorrectly; e.g., importing named export instead of default.
fix
Use import autocannon from 'autocannon' (default import).
error connect ECONNREFUSED 127.0.0.1:3000
cause Target server is not running or port is wrong.
fix
Ensure the server is running on the specified port; check URL and port.
breaking autocannon v8 dropped CommonJS support; requires ESM imports.
fix Update imports to use ESM syntax; do not use require().
deprecated The 'printResult' function is deprecated in favor of 'autocannon.print'. In v8, 'printResult' may be removed.
fix Replace autocannon.printResult(output, result) with autocannon.print(output, result).
gotcha When using '--workers', the callback in the programmatic API is not called; results are only available via track or event listeners.
fix Use autocannon.track() or listen for 'done' event on the instance.
gotcha Setting both 'amount' and 'duration' will cause 'duration' to be ignored.
fix Use only one of 'amount' or 'duration' at a time.
gotcha When using a custom 'requestIterator', the 'requests' option inside the iterator must be an array of objects with 'method', 'path', etc., not just strings.
fix Ensure the 'requests' array contains objects with 'method', 'path', 'headers', 'body' as needed.
npm install autocannon
yarn add autocannon
pnpm add autocannon

Runs a 10-second benchmark with 10 concurrent connections against a local server and prints progress to console.

import autocannon from 'autocannon';

const instance = autocannon({
  url: 'http://localhost:3000',
  connections: 10,
  duration: 10,
}, (err, result) => {
  if (err) {
    console.error(err);
    return;
  }
  console.log(result);
});

autocannon.track(instance);