The `wrk` Node.js package serves as a wrapper for the popular `wrk` HTTP benchmarking command-line tool. It enables developers to programmatically execute load tests and parse the output directly within a Node.js environment, simplifying the integration of performance testing into applications or CI/CD pipelines. This package allows configuration of `wrk` parameters such as threads, connections, and test duration, and then processes the `wrk` tool's raw output into a structured JavaScript object containing detailed performance metrics like requests per second, latency statistics, and transfer rates. Currently at version 1.2.1, the package was last published in September 2020, indicating it is no longer actively maintained. Its primary utility lies in abstracting the `child_process` execution and output parsing, but it critically depends on the `wrk` CLI tool being pre-installed on the system and accessible in the PATH.
npm install wrkVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use the `node-wrk` package to perform a series of load tests, incrementally increasing the number of concurrent connections. It shows how to configure `wrk` options, handle the callback, and accumulate results, providing a basic framework for performance analysis.
Install the `wrk` command-line tool according to its official documentation (e.g., `brew install wrk` on macOS, compile from source on Linux).
For critical applications, consider using `wrk` directly via `child_process` or exploring alternative, actively maintained Node.js load testing solutions.
Use `const wrk = require('wrk');` in CommonJS environments. In ESM, use `const { default: wrk } = await import('wrk');`.Consider creating a declaration file (`wrk.d.ts`) with `declare module 'wrk';` or more specific type definitions for the `wrk` function and its `wrkResults` output structure.
Ensure the `wrk` CLI tool is installed and accessible globally. For example, on macOS: `brew install wrk`. On Linux, you might need to compile it from source (refer to the official `wrk` GitHub page).
While `node-wrk` is CJS, if your project is pure ESM, ensure Node.js is configured to allow CJS modules. Or, if you are mistakenly trying to import another ESM-only package with `require`, change it to `import`.
For CommonJS, use `const wrk = require('wrk');`. For ESM (via dynamic import), use `const { default: wrk } = await import('wrk');` to correctly access the default exported function.