NAPI-RS is a framework for building pre-compiled Node.js addons in Rust.
Rustify Node.js in few lines!
lib.rs
use napi_derive::napi;
#[napi]
fn fibonacci(n: u32) -> u32 {
match n {
1 | 2 => 1,
_ => fibonacci(n - 1) + fibonacci(n - 2),
}
}
Compatible with both CommonJS
and esm
, with auto generated .d.ts
file:
main.mjs
import { fibonacci } from './index.js'
// output: 5
console.log(fibonacci(5))
main.cjs
const { fibonacci } = require('./index')
// output: 5
console.log(fibonacci(5))
Features
🚀 Bring native performance for Node.js
👷♂️ Memory safe, guaranteed by Rust
compiler
⚡️ Zero copy data interactive between Rust
& Node.js
via Buffer
and TypedArray
⚙️ Parallelism in few lines
Sponsors
Ecosystem
AFFiNEPolarsLogseqFormat.JSPerfseeDatabendRspackHugging FacedittoLoroRollup
Support matrix
Node.js
Node10 | Node12 | Node14 | Node16 | Node18 | Node20 |
---|---|---|---|---|---|
✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
Platform support
✅ Means official tested in napi-rs repo.
-
Means no official Node.js release.
i686 | x64 | aarch64 | arm | |
---|---|---|---|---|
Windows | ✅ | ✅ | ✅ | - |
macOS | - | ✅ | ✅ | ✅ |
Linux | - | ✅ | ✅ | ✅ |
Linux musl | - | ✅ | ✅ | - |
FreeBSD | - | ✅ | - | - |
Android | - | - | ✅ | ✅ |