{"id":15939,"library":"wrk","title":"wrk Load Test Tool Wrapper","description":"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.","status":"abandoned","version":"1.2.1","language":"javascript","source_language":"en","source_url":"https://github.com/sidorares/node-wrk","tags":["javascript","wrk","load test"],"install":[{"cmd":"npm install wrk","lang":"bash","label":"npm"},{"cmd":"yarn add wrk","lang":"bash","label":"yarn"},{"cmd":"pnpm add wrk","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"This Node.js package is a wrapper for the external `wrk` command-line HTTP benchmarking tool. The `wrk` CLI tool must be installed and accessible in the system's PATH for this package to function.","package":"wrk (CLI tool)","optional":false}],"imports":[{"note":"The package is CommonJS-only and exports a single function as its default. This is the only supported import method.","symbol":"wrk","correct":"const wrk = require('wrk');"},{"note":"While Node.js can sometimes import CommonJS modules via `import`, `node-wrk` does not provide an explicit ESM export. Direct `import wrk from 'wrk'` will likely fail. You must use dynamic `import` and access the `default` property.","wrong":"import wrk from 'wrk';","symbol":"wrk","correct":"const { default: wrk } = await import('wrk');"}],"quickstart":{"code":"const wrk = require('wrk');\n\nlet conns = 1;\nconst results = [];\n\nfunction benchmark() {\n  if (conns === 100) {\n    // In a real scenario, you'd process these results,\n    // e.g., save to a file, aggregate, or display.\n    console.log('--- Benchmark Complete ---');\n    results.forEach((res, index) => {\n      console.log(`\nTest with ${res.connections} connections:`);\n      console.log(`  Requests/Sec: ${res.requestsPerSec}`);\n      console.log(`  Latency Avg: ${res.latencyAvg}`);\n    });\n    return;\n  }\n  \n  console.log(`Running test with ${conns} connections...`);\n  wrk({\n    threads: 1,\n    connections: conns,\n    duration: '1s',\n    printLatency: true,\n    headers: { 'User-Agent': 'node-wrk-benchmark' },\n    url: 'http://localhost:3000/' // Ensure a server is running here, e.g., 'python3 -m http.server 3000'\n  }, function(err, out) {\n     if (err) {\n       console.error('wrk error:', err);\n       // Often 'spawn wrk ENOENT' if the wrk CLI tool is not installed or in PATH\n       return;\n     }\n     results.push(out);\n     conns++;\n     benchmark();\n  });\n}\n\n// To run this example, ensure the `wrk` CLI tool is installed (e.g., `brew install wrk` on macOS)\n// and a simple HTTP server is running on http://localhost:3000.\n// You can start a simple Python server with: `python3 -m http.server 3000`\n\nbenchmark();","lang":"javascript","description":"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."},"warnings":[{"fix":"Install the `wrk` command-line tool according to its official documentation (e.g., `brew install wrk` on macOS, compile from source on Linux).","message":"The `node-wrk` package is a wrapper for the external `wrk` command-line tool. The `wrk` CLI tool *must* be installed on your system and accessible via the system's PATH environment variable for this package to function. This is not an npm dependency.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"For critical applications, consider using `wrk` directly via `child_process` or exploring alternative, actively maintained Node.js load testing solutions.","message":"The `node-wrk` package is no longer actively maintained. Its last publish was in September 2020. This means it may not receive updates for new Node.js versions, security vulnerabilities, or new features from the underlying `wrk` CLI tool.","severity":"gotcha","affected_versions":">=1.2.1"},{"fix":"Use `const wrk = require('wrk');` in CommonJS environments. In ESM, use `const { default: wrk } = await import('wrk');`.","message":"This package is CommonJS-only (`require`). It does not provide native ECMAScript Module (ESM) exports. Attempting a direct `import wrk from 'wrk'` will fail without specific build configurations or dynamic import (`await import('wrk')`).","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"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.","message":"The package does not ship with TypeScript type definitions, which can lead to a less type-safe development experience when used in TypeScript projects.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"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).","cause":"The `wrk` command-line tool is not installed on the system or is not found in the system's PATH environment variable. The `node-wrk` package is just a wrapper and does not install the `wrk` binary itself.","error":"Error: spawn wrk ENOENT"},{"fix":"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`.","cause":"This error occurs when trying to use `require()` to import a package that is exclusively an ESM module. Although this package is CommonJS, this error might occur if `node-wrk` is integrated into a project that itself is configured as ESM-only and doesn't handle CJS interop correctly.","error":"ERR_REQUIRE_ESM: require() of ES Module ... is not supported."},{"fix":"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.","cause":"This usually happens if the import statement is incorrect, such as `import { wrk } from 'wrk';` or `import * as wrk from 'wrk';` in an ESM context, where the package actually exports a default function.","error":"TypeError: wrk is not a function"}],"ecosystem":"npm"}