Knitting is a worker pool for Node.js, Deno, and Bun, with a focus on HTTP servers and request offloading. It runs JavaScript and TypeScript functions in threads or separate processes. Calls use shared memory, and results come back as promises.
Website: js.knitting.run
For agents, the website provides a compact documentation map in
llms.txt and full documentation in
llms-full.txt.
Knitting specializes in:
- Offloading CPU-heavy work from HTTP request handlers.
- Parsing and validating request bodies.
- Server-side rendering and compression.
- Sharing large buffers between workers.
- Running tasks across threads and processes.
Documentation · API guide · Source map · Discord
npm install knittingFor Deno, use deno add --npm knitting.
Save this as example.mjs:
import { createPool, isMain } from "knitting";
export const square = (value) => value * value;
export const greet = (name) => `hello ${name}`;
if (isMain) {
const pool = createPool({ threads: 2 })({ square, greet });
try {
const [four, message] = await Promise.all([
pool.call.square(2),
pool.call.greet("knitting"),
]);
console.log({ four, message });
} finally {
await pool.shutdown();
}
}Run it with Node.js, Bun, or Deno:
node example.mjs
bun example.mjs
deno run -A example.mjsThe result is { four: 4, message: "hello knitting" }.
Export your functions so workers can load them. Keep pool creation inside
if (isMain) so workers don't create pools of their own. Call shutdown() when
you're done; finally makes sure it also runs if a task fails.
This example works on Node.js 22. Runtimes with await using can use it for
cleanup instead; see pool cleanup.
Deno's -A grants all permissions for the example.
- Typed function calls across threads and processes.
- Timeouts and cancellation.
- JSON, typed arrays, and shared buffers.
- Work stealing and scheduling options.
- Browser support for pages with cross-origin isolation enabled.
See the API guide for configuration and experimental backends.
Knitting requires Node.js 22+, Deno 2+, or Bun 1+. The test workflow covers Linux, macOS, and Windows; check it for tested versions and results.
Node.js native addons are packaged for 22 and 24 on Linux x64, macOS x64/arm64, and Windows x64. Node.js 26 has an experimental FFI backend. See native support for details.
Permissions depend on the runtime and worker type. Read the permission guide when setting up process isolation.
Shared memory can reduce the cost of sending work to a worker. How much it helps depends on the task, payload, runtime, and pool settings.
./run.sh --json --bench=doorbell --runtime=nodeSee the benchmarks for commands, measurements, and reports. Compare repeated runs with the same settings, and test your own workload before drawing conclusions.
Bun runs the build scripts. Install Node.js and Deno too if you want to test all three runtimes.
bun install --frozen-lockfile
bun run build
npm run test:node
npm run test:bun
npm run test:denoSee Contributing for native builds, browser tests, and pull requests. Report security issues using the security policy.