Python ctypes for Node.js. A foreign function interface built with C++20,
node-addon-api and aotffi
(zero-JIT AOT C++20 + assembly backend).
If you know Python ctypes, you already know node-ctypes.
Development help is welcome: issues, pull requests and discussions are all appreciated.
If you find node-ctypes useful, consider :star: this project and why not ... Buy me a coffee :smile:
npm install node-ctypes
Prebuilt binaries ship for Windows, macOS 13.5+ and Linux (glibc 2.28+ or musl / Alpine), on x64 and ARM64 — wherever Node 24 runs.
import { CDLL, Structure, c_int32, c_size_t, c_char_p } from "node-ctypes";
// 1. Load a shared library
const libc = new CDLL(process.platform === "win32" ? "msvcrt" : null);
// 2. Declare a function signature
const strlen = libc.strlen;
strlen.argtypes = [c_char_p];
strlen.restype = c_size_t;
console.log(strlen("hello")); // 5n
// 3. Declare a struct
class Point extends Structure {
static _fields_ = [
["x", c_int32],
["y", c_int32],
];
}
const p = new Point(3, 4);
console.log(p.x, p.y); // 3 4
To build from source, see Getting started.
JavaScript runs on one thread. A C function called synchronously blocks it, so a
threadSafeCallback invoked by another thread cannot run until that call returns.
Never wait synchronously (WaitForSingleObject, pthread_join, …) for a thread
that calls a threadSafeCallback: the two threads would wait for each other.
Make such waits asynchronous with callAsync() or callOn(); see
Callbacks from other threads.
| Operating system | x64 | ARM64 | Minimum version |
|---|---|---|---|
| Windows | ✅ | ✅ | |
| macOS | ✅ | ✅ | macOS 13.5 |
| Linux, glibc | ✅ | ✅ | glibc 2.28 |
| Linux, musl (Alpine) | ✅ | ✅ |
Node.js 24 or later. Details, testing and building from source are in Getting started.
cast, shared buffers, native memory, ElectroncallAsync and the Executorerrno, GetLastError, errcheck, output parameterswintypesEach example in examples/ has its own README; see the index.
winscard on Windows, PCSC.framework on macOS, libpcsclite on LinuxIShellLinkW) and Active Directory (IDirectorySearch)wldap32)setValue / getValue / openKey / deleteKeyMIT. Built with node-addon-api and cmake-js.