A high-performance Node.js FFI module written in Rust and N-API for calling C/C++/Rust functions from JavaScript.
ffi-rs is a Node.js module that provides Foreign Function Interface (FFI) capabilities, allowing JavaScript code to call functions from native libraries written in C, C++, or Rust. It solves the problem of integrating low-level system libraries or performance-critical native code into Node.js applications without writing C++ bindings.
Node.js developers who need to interface with existing C/C++/Rust libraries, system-level programmers integrating native code, or those building high-performance modules requiring direct hardware or OS access.
Developers choose ffi-rs for its superior performance over older FFI solutions, modern Rust-based reliability, comprehensive type support, and the ability to run FFI calls in separate threads to avoid blocking the event loop.
Implement ffi in Node.js by Rust and NAPI
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Benchmarks show it's over 150 times faster than ffi-napi, with 318,467 ops/s versus 2,028 ops/s, making it ideal for high-throughput FFI calls.
Handles basic types, arrays, structs, pointers, and C++ classes, enabling complex integrations without writing C++ code, as detailed in the supported types list.
Supports running FFI tasks in new threads via the runInNewThread option, preventing the main Node.js event loop from being blocked during CPU-intensive operations.
Built with Rust and N-API, it's actively maintained as a replacement for the unmaintained node-ffi, offering better safety and reliability.
Requires explicit memory freeing using functions like freePointer, which is error-prone and can lead to leaks if not handled carefully, as noted in the memory management section.
Limited to listed platforms, and dynamic libraries must be compiled for the exact runtime environment, adding complexity to deployment and cross-platform development.
Handling pointers, structs, and arrays involves multiple helper functions (e.g., createPointer, unwrapPointer), increasing the learning curve and potential for misuse.
node-ffi-rs is an open-source alternative to the following products: