Node.js is getting a built-in node:ffi module. It lets you load shared libraries and call native functions directly from JavaScript, without any kind of wrappers or extra build step. I just heard that it landed in the upstream git repo about an hour ago, and should appear in Node 26.
Here’s what it looks like:
import { dlopen } from 'node:ffi';
const { functions } = dlopen(`libsqlite3.so`, {
sqlite3_libversion: { parameters: [], result: 'string' },
});
console.log(functions.sqlite3_libversion());
That’s it. Load a .so, declare the signature, call the function. Callbacks work too. You can pass JavaScript functions as native function pointers to your C code.
This is interesting to me, as I created libffi 30 years ago last month. It started as a way to build a generic calling convention bridge for the GNU java compiler and runtime, but now it’s bundled as a core language feature in each of Python, Ruby, and (as of this module) Node.js, along with a number of Java ports.
Here’s a good walkthrough of the implementation:
Congratulations to the Node team for landing this!