A framework for building compiled Node.js add-ons in Rust via Node-API
open sourceMITfree
napi-rs is a framework for writing pre-compiled Node.js add-ons in Rust through Node-API. Annotating Rust functions and structs with #[napi] generates the JavaScript bindings and TypeScript type definitions, and the napi CLI builds the add-on with no hand-written glue, cross-compiles it for other platforms, sets up CI and publishes a package per platform to npm. It can also compile the same code to WebAssembly, and its API design manages lifetimes for safety. It's released under the MIT licence.
Problems it solves
- write the slow part of my Node.js library in Rust and call it from JavaScript
- ship a native Node.js add-on with prebuilt binaries so users don't need a compiler
- generate TypeScript types for my Rust bindings automatically
- cross-compile my Rust Node module for Linux, macOS, Windows and ARM in CI
- run the same Rust code natively in Node.js and as WebAssembly in the browser
Features
- #[napi] macros generate JavaScript bindings and TypeScript definitions
- napi build: zero-config build of the add-on
- Cross-compilation for many platforms
- CI templates and per-platform npm packages
- WebAssembly target from the same code
- Lifetime-managed, safer API design
Capabilities
| Has a command line tool | plan not known |
|---|
Alternatives
The same job
These do what napi-rs does.
- bindgen Generates Rust FFI bindings to C and some C++ libraries from their headers
- wasm-bindgen Generates the glue between Rust WebAssembly modules and JavaScript
- flutter_rust_bridge Call Rust code from Flutter and Dart, with the glue code generated for you
