- Use
#[napi]macro for Node.js-visible functions and classes. Use#[napi(constructor)]for constructors. - Map Rust errors to JavaScript
Errorobjects vianapi::Error. ReturnResult<T>from all fallible functions. - Use
napi::bindgen_prelude::*for common type conversions. UseBufferfor binary data. - Support both CommonJS and ESM output. Generate
.d.tstype definitions automatically. - Use
#[napi(ts_return_type = "...")]for complex TypeScript types the macro can't infer. - Build with
napi build --release. Test from TypeScript/JavaScript using a JS test runner (e.g., Vitest or Jest). - Async: use
#[napi]onasync fnfor Promise-returning functions. UseAsyncTaskfor CPU-bound work. - Keep Node.js wrappers thin — business logic in Rust, JS provides idiomatic API.
- Handle
BigInt,Date, and other JS-specific types explicitly. - Anti-patterns: no panics in napi functions, no blocking the event loop, no manual
JsValuemanipulation.
Napi Rs Bindings
napi-rs conventions for exposing a Rust core to Node.js: #[napi] macros, napi::Error mapping, auto-generated .d.ts types, async Promises, and CommonJS/ESM output. Load when generating or reviewing napi-rs Node.js bindings for a Rust library.
Napi Rs Bindings by goldziher · d5bd184
npx skillmds@latest add goldziher/napi-rs-bindings File contents
---name: napi-rs-bindingsdescription: napi-rs conventions for exposing a Rust core to Node.js: #[napi] macros, napi::Error mapping, auto-generated .d.ts types, async Promises, and CommonJS/ESM output. Load when generating or reviewing napi-rs Node.js bindings for a Rust library.---- Use `#[napi]` macro for Node.js-visible functions and classes. Use `#[napi(constructor)]` for constructors.- Map Rust errors to JavaScript `Error` objects via `napi::Error`. Return `Result<T>` from all fallible functions.- Use `napi::bindgen_prelude::*` for common type conversions. Use `Buffer` for binary data.- Support both CommonJS and ESM output. Generate `.d.ts` type definitions automatically.- Use `#[napi(ts_return_type = "...")]` for complex TypeScript types the macro can't infer.- Build with `napi build --release`. Test from TypeScript/JavaScript using a JS test runner (e.g., Vitest or Jest).- Async: use `#[napi]` on `async fn` for Promise-returning functions. Use `AsyncTask` for CPU-bound work.- Keep Node.js wrappers thin — business logic in Rust, JS provides idiomatic API.- Handle `BigInt`, `Date`, and other JS-specific types explicitly.- Anti-patterns: no panics in napi functions, no blocking the event loop, no manual `JsValue` manipulation.
goldziher/ai-rulez/tree/main/internal/builtins/bindings/napi-rs/skills/napi-rs-bindings commit d5bd1847e9
Frequently asked questions
Run npx skillmds@latest add goldziher/napi-rs-bindings in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
napi-rs conventions for exposing a Rust core to Node.js: #[napi] macros, napi::Error mapping, auto-generated .d.ts types, async Promises, and CommonJS/ESM output. Load when generating or reviewing napi-rs Node.js bindings for a Rust library. It is listed under Coding & Dev Tools on SkillMD.
This skill has not completed SkillMD's automated safety review yet. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Yes. Installing skills from SkillMD is free, and the skill stays under its author's original license.
goldziher (@goldziher) published this skill. Their other Agent Skills are listed on their SkillMD profile.