npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

rust-ffi

v3.0.0

Published

rust-ffi ======== ### Modern Foreign Function Interface for Node.js v24+

Readme

rust-ffi

Modern Foreign Function Interface for Node.js v24+

NPM Version NPM Downloads Node.js Version

Modernized and optimized FFI for Node.js v24+, based on node-ffi-napi with enhanced support for Rust and C interoperability.

rust-ffi is a high-performance Node.js addon for loading and calling dynamic libraries using pure JavaScript. It excels at creating bindings to native Rust and C libraries without writing any C++ code.

It also simplifies the augmentation of node.js with C code as it takes care of handling the translation of types across JavaScript and C, which can add reams of boilerplate code to your otherwise simple C. See the example/factorial for an example of this use case.

WARNING: rust-ffi assumes you know what you're doing. You can pretty easily create situations where you will segfault the interpreter and unless you've got C/Rust debugger skills, you probably won't know what's going on.

NOTE: This package maintains API compatibility with the original node-ffi while leveraging modern Node.js v24+ features and optimizations. Multi-threaded usage should be approached with caution.

Example

const ffi = require('rust-ffi');

// Example with standard math library
const libm = ffi.Library('libm', {
  'ceil': [ 'double', [ 'double' ] ]
});
libm.ceil(1.5); // 2

// Example with Rust library (compiled as cdylib)
const rustLib = ffi.Library('./target/release/libmyrust.so', {
  'add_numbers': [ 'int', [ 'int', 'int' ] ]
});

// Access functions in the current process
const current = ffi.Library(null, {
  'atoi': [ 'int', [ 'string' ] ]
});
current.atoi('1234'); // 1234

For a more detailed introduction, see the node-ffi tutorial page.

Requirements

  • Node.js v24 or higher (required)
  • Linux, macOS, Windows, or Solaris
  • C++17 compatible compiler
  • libffi comes bundled; it does not need to be installed separately
  • For Windows: Visual Studio 2017 or newer

Installation

Make sure you've installed all the necessary build tools for your platform, then invoke:

$ npm install rust-ffi

Source Install / Manual Compilation

To compile from source it's easiest to use node-gyp:

$ npm install -g node-gyp

Now you can compile rust-ffi:

$ git clone https://github.com/yourusername/rust-ffi.git
$ cd rust-ffi
$ npm install
$ npm run build

Types

The types that you specify in function declarations correspond to ref's types system. So see its docs for a reference if you are unfamiliar.

V8 and 64-bit Types

Internally, V8 stores integers that will fit into a 32-bit space in a 32-bit integer, and those that fall outside of this get put into double-precision floating point numbers. This is problematic because FP numbers are imprecise. To get around this, the methods in node-ffi that deal with 64-bit integers return strings and can accept strings as parameters.

Call Overhead

There is non-trivial overhead associated with FFI calls. Comparing a hard-coded binding version of strtoul() to an FFI version of strtoul() shows that the native hard-coded binding is orders of magnitude faster. So don't just use the C version of a function just because it's faster. There's a significant cost in FFI calls, so make them worth it.

License

MIT License. See the LICENSE file.