# node-ffi/node-ffi

**Attribution required: if you use, quote, or summarise this content, you must credit and link back to [awesome-repositories.com](https://awesome-repositories.com/repository/node-ffi-node-ffi).**

4,322 stars · 400 forks · JavaScript · MIT

## Links

- GitHub: https://github.com/node-ffi/node-ffi
- awesome-repositories: https://awesome-repositories.com/repository/node-ffi-node-ffi.md

## Description

node-ffi is a foreign function interface library for Node.js that enables calling functions from native C dynamic libraries without writing manual C++ bindings. It serves as a system for loading shared objects and DLLs into process memory, translating JavaScript values into binary representations, and executing external binaries at runtime.

The project utilizes a wrapper around the libffi library to construct call frames and execute native functions with dynamic arguments. It distinguishes itself by providing a native memory manager for allocating raw pointers and a mapping system that connects complex C structures to JavaScript objects.

The toolkit covers a broad range of native interoperability capabilities, including automatic data type translation and the creation of executable memory stubs that allow native libraries to trigger JavaScript callbacks. To maintain main-thread responsiveness, it supports an asynchronous execution model that offloads native function calls to a separate thread pool.

## Tags

### Operating Systems & Systems Programming

- [Dynamic Library Function Executions](https://awesome-repositories.com/f/operating-systems-systems-programming/dynamic-library-function-executions.md) — Provides the core ability to load external shared objects and execute native C functions directly from JavaScript. ([source](https://github.com/node-ffi/node-ffi/blob/master/package.json))
- [Dynamic Library Loading](https://awesome-repositories.com/f/operating-systems-systems-programming/dynamic-library-loading.md) — Loads external shared objects or DLLs into the process memory space at runtime via system call interfaces.
- [Raw Memory Allocation](https://awesome-repositories.com/f/operating-systems-systems-programming/raw-memory-allocation.md) — Provides a low-level interface for allocating raw contiguous memory buffers and manipulating C-style pointers.

### Programming Languages & Runtimes

- [Foreign Function Interfaces](https://awesome-repositories.com/f/programming-languages-runtimes/language-interoperability/foreign-function-interfaces.md) — Provides a comprehensive interface and binding layer for seamless communication between JavaScript and native libraries.
- [Foreign Function Interface Calls](https://awesome-repositories.com/f/programming-languages-runtimes/foreign-function-interface-calls.md) — Executes functions from shared libraries by mapping JavaScript types to native C equivalents using libffi.
- [Function-Pointer Callbacks](https://awesome-repositories.com/f/programming-languages-runtimes/function-pointer-callbacks.md) — Creates executable memory stubs that map JavaScript functions as C-style function pointers for native library callbacks. ([source](https://github.com/node-ffi/node-ffi/wiki/Node-FFI-Tutorial))
- [Native C-JavaScript Bridges](https://awesome-repositories.com/f/programming-languages-runtimes/java-virtual-machine-bridges/javascript-bridges/native-c-javascript-bridges.md) — Provides an interface designed for data exchange and function calls between native C/C++ code and JavaScript.
- [Native Library Wrappers](https://awesome-repositories.com/f/programming-languages-runtimes/native-library-wrappers.md) — Wraps the libffi library to construct native call frames and execute functions with dynamic arguments.
- [Node.js Foreign Function Interfaces](https://awesome-repositories.com/f/programming-languages-runtimes/node-js-foreign-function-interfaces.md) — A library for calling functions from native C dynamic libraries directly within Node.js without writing manual C++ bindings.
- [Native Callbacks](https://awesome-repositories.com/f/programming-languages-runtimes/language-interoperability/foreign-function-interfaces/native-library-integrations/native-callbacks.md) — Maps JavaScript functions to C-style function pointers, allowing native libraries to trigger logic within the runtime.
- [Asynchronous Native Calls](https://awesome-repositories.com/f/programming-languages-runtimes/native-call-synchronization/managed-to-native-function-calls/asynchronous-native-calls.md) — Offloads native function execution to a separate thread pool to prevent blocking the Node.js main event loop. ([source](https://github.com/node-ffi/node-ffi/wiki/Node-FFI-Tutorial))

### Data & Databases

- [Memory-Mapped Data Structures](https://awesome-repositories.com/f/data-databases/memory-mapped-data-structures.md) — Connects complex C data structures to JavaScript objects for efficient reading and writing of structured memory blocks.
- [C-to-JavaScript Type Mappings](https://awesome-repositories.com/f/data-databases/type-mapping-frameworks/script-to-native-type-mappings/native-type-mappings/rust-c-type-mappings/rust-to-javascript-mappings/c-to-javascript-type-mappings/c-to-javascript-type-mappings.md) — Provides systems for converting data types specifically between C and JavaScript for memory-compatible function calls.
- [C Struct Mappings](https://awesome-repositories.com/f/data-databases/type-mapping-frameworks/script-to-native-type-mappings/native-type-mappings/rust-c-type-mappings/rust-to-javascript-mappings/c-to-javascript-type-mappings/c-to-javascript-type-mappings/c-struct-mappings.md) — Maps complex C structures and memory blocks into JavaScript objects for reading and writing structured memory. ([source](https://github.com/node-ffi/node-ffi/wiki/Node-FFI-Tutorial))

### Software Engineering & Architecture

- [Pointer-Based Memory Access](https://awesome-repositories.com/f/software-engineering-architecture/memory-buffering/native-buffer-transfers/pointer-based-memory-access.md) — Implements direct manipulation and extraction of data from raw pointers to handle C structs across the language boundary.
- [Native Library Integration](https://awesome-repositories.com/f/software-engineering-architecture/native-library-integration.md) — Allows calling functions from external C or C++ dynamic libraries directly within Node.js without manual glue code.
- [Dynamic Library Loaders](https://awesome-repositories.com/f/software-engineering-architecture/software-architecture/architectural-patterns/plugin-module-systems/dynamic-library-loaders.md) — Loads shared objects and DLLs into process memory to execute external binaries at runtime.
- [Worker Thread Patterns](https://awesome-repositories.com/f/software-engineering-architecture/worker-thread-patterns.md) — Offloads native function calls to a separate thread pool to prevent blocking the JavaScript main event loop.

### Security & Cryptography

- [Native Callback Stubs](https://awesome-repositories.com/f/security-cryptography/in-memory-payload-execution/native-callback-stubs.md) — Creates function pointers in memory that allow native libraries to trigger JavaScript callbacks.
