title | description |
---|---|
Home |
NAPI-RS is a framework for building Node.js addons in Rust. |
import { Badges } from '../components/badges' import { Rust } from '../components/chalk' import { Ecosystem } from '../components/ecosystem' import { Sponsors } from '../components/sponsors' import { TitleEN } from '../components/title.en'
export const getStaticProps = async () => {
const sponsorsSVG = await fetch(https://sponsors.napi.rs/sponsors.svg
).then(
(res) => res.text(),
)
return {
props: {
ssg: sponsorsSVG,
},
}
}
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:
import { fibonacci } from './index.js'
// output: 5
console.log(fibonacci(5))
const { fibonacci } = require('./index')
// output: 5
console.log(fibonacci(5))
🚀 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
Node10 | Node12 | Node14 | Node16 | Node18 | Node20 |
---|---|---|---|---|---|
✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
✅ Means official tested in napi-rs repo.
-
Means no official Node.js release.
i686 | x64 | aarch64 | arm | |
---|---|---|---|---|
Windows | ✅ | ✅ | ✅ | - |
macOS | - | ✅ | ✅ | ✅ |
Linux | - | ✅ | ✅ | ✅ |
Linux musl | - | ✅ | ✅ | - |
FreeBSD | - | ✅ | - | - |
Android | - | - | ✅ | ✅ |