Nub: A Rust-Powered All-in-One Toolkit for Node.js
Nub: A Rust-Powered All-in-One Toolkit for Node.js
Nub is a fast, all-in-one toolkit written in Rust that augments the stock Node.js runtime rather than replacing it. It aims to provide a developer experience (DX) similar to Bun or Deno—offering built-in TypeScript support, a high-performance package manager, and integrated version management—while remaining fully compatible with the existing Node.js ecosystem and avoiding vendor-specific API lock-in.
High-Performance Tooling and Benchmarks
Nub replaces several common JavaScript-based tools with Rust binaries to eliminate the startup lag associated with spawning Node.js processes. This results in significant performance gains across the development lifecycle.
Script and Package Execution
Nub's script runner (nub run) and package runner (nubx) are designed as drop-in replacements for npm run, pnpm run, npx, and pnpm dlx.
- Script Dispatch:
nub runis approximately 24× faster thanpnpm runand 22× faster thannpm run, with a warm dispatch time of 14.7ms compared to 329.9ms for npm and 442.7ms for pnpm. - Package Execution:
nubxexecutes local binaries roughly 19× faster thannpxby eliminating the double-Node.js-spawn penalty.
Package Management
Powered by the Aube engine, nub install is a flag-compatible replacement for pnpm. In benchmarks for a warm frozen install of a project with 222 dependencies, Nub outperformed other managers:
| Tool | Time | Relative Performance |
|---|---|---|
| Nub | 1122 ms | — |
| Bun | 1444 ms | 29% slower |
| pnpm | 2847 ms | 2.5× slower |
| npm | 4163 ms | 3.7× slower |
TypeScript-First Node.js Runtime
Nub allows developers to run .ts, .tsx, .js, and .jsx files directly without a separate build step. It is 2.9× faster at startup than tsx.
Technical Implementation
Nub leverages modern Node.js extension surfaces to provide its augmentations:
- Transpilation: It embeds the
oxclibrary for pre-transpilation. - Hooks: It uses
module.registerHooks()and--import/--requirepreloads for custom transpilation and resolution. - Native Addons: It utilizes N-API native addons to integrate Rust-based logic into the Node.js process.
Language and API Support
Nub provides comprehensive support for modern JavaScript and TypeScript features:
- TypeScript Support: Full support for
enum,namespace, extensionless imports, andtsconfig.json#pathsresolution. - Modern APIs: Nub automatically polyfills APIs like
Temporal,URLPattern, andRegExp.escapeon older Node versions and unflags experimental Node.js features such asnode:sqlite,vm.Module, andWebSocket. - Environment Management: Automatic
.env*loading is built-in, providing parity with Next.js and Vite.
Integrated Node.js Ecosystem Management
Nub consolidates several fragmented tools into a single binary, managing both the project dependencies and the Node.js runtime itself.
Node Version Management
Nub acts as a version manager similar to nvm or fnm. It can manually provision versions via nub node install or automatically infer the required Node version from .node-version, .nvmrc, package.json#engines, or package.json#devEngines and install it on the fly.
Package Manager Compatibility
Nub can operate in "compat-mode," detecting the incumbent package manager (npm, pnpm, Bun, or Yarn) based on lockfiles or package.json settings. In this mode, it respects the specific configuration files (e.g., pnpm-lock.yaml or bunfig.toml) and environment variables of the incumbent tool.
Package Meta-Management
Through nub pm shim, Nub provides a Rust-native implementation of Corepack's functionality, registering global shims for npm, yarn, and pnpm to ensure the correct version of the package manager is used for a given project.