{"id":15049513,"url":"https://github.com/httptoolkit/node-ffi-napi","last_synced_at":"2025-10-04T10:31:11.215Z","repository":{"id":57116679,"uuid":"249707629","full_name":"httptoolkit/node-ffi-napi","owner":"httptoolkit","description":"A foreign function interface (FFI) for Node.js, N-API style","archived":false,"fork":true,"pushed_at":"2020-04-23T15:16:51.000Z","size":3581,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-05-01T11:09:37.720Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"node-ffi-napi/node-ffi-napi","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/httptoolkit.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-03-24T12:53:19.000Z","updated_at":"2020-03-24T15:21:10.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/httptoolkit/node-ffi-napi","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/httptoolkit%2Fnode-ffi-napi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/httptoolkit%2Fnode-ffi-napi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/httptoolkit%2Fnode-ffi-napi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/httptoolkit%2Fnode-ffi-napi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/httptoolkit","download_url":"https://codeload.github.com/httptoolkit/node-ffi-napi/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":235238234,"owners_count":18958062,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-09-24T21:21:04.511Z","updated_at":"2025-10-04T10:31:05.425Z","avatar_url":"https://github.com/httptoolkit.png","language":"JavaScript","readme":"node-ffi-napi\n=============\n### Node.js Foreign Function Interface for N-API\n[![Greenkeeper badge](https://badges.greenkeeper.io/node-ffi-napi/node-ffi-napi.svg)](https://greenkeeper.io/)\n\n[![NPM Version](https://img.shields.io/npm/v/ffi-napi.svg?style=flat)](https://npmjs.org/package/ffi-napi)\n[![NPM Downloads](https://img.shields.io/npm/dm/ffi-napi.svg?style=flat)](https://npmjs.org/package/ffi-napi)\n[![Build Status](https://travis-ci.org/node-ffi-napi/node-ffi-napi.svg?style=flat\u0026branch=master)](https://travis-ci.org/node-ffi-napi/node-ffi-napi?branch=master)\n[![Coverage Status](https://coveralls.io/repos/node-ffi-napi/node-ffi-napi/badge.svg?branch=master)](https://coveralls.io/r/node-ffi-napi/node-ffi-napi?branch=master)\n[![Dependency Status](https://david-dm.org/node-ffi-napi/node-ffi-napi.svg?style=flat)](https://david-dm.org/node-ffi-napi/node-ffi-napi)\n\n`node-ffi-napi` is a Node.js addon for loading and calling dynamic libraries\nusing pure JavaScript. It can be used to create bindings to native libraries\nwithout writing any C++ code.\n\nIt also simplifies the augmentation of node.js with C code as it takes care of\nhandling the translation of types across JavaScript and C, which can add reams\nof boilerplate code to your otherwise simple C. See the `example/factorial`\nfor an example of this use case.\n\n**WARNING**: `node-ffi-napi` assumes you know what you're doing. You can pretty\neasily create situations where you will segfault the interpreter and unless\nyou've got C debugger skills, you probably won't know what's going on.\n\n**WARNING**: The original API of `node-ffi` is left mostly untouched in the\nN-API wrapper. However, the API did not have very well-defined properties\nin the context of garbage collection and multi-threaded execution. It is\nrecommended to avoid any multi-threading usage of this library\nif possible.\n\nExample\n-------\n\n``` js\nvar ffi = require('ffi-napi');\n\nvar libm = ffi.Library('libm', {\n  'ceil': [ 'double', [ 'double' ] ]\n});\nlibm.ceil(1.5); // 2\n\n// You can also access just functions in the current process by passing a null\nvar current = ffi.Library(null, {\n  'atoi': [ 'int', [ 'string' ] ]\n});\ncurrent.atoi('1234'); // 1234\n```\n\nFor a more detailed introduction, see the [node-ffi tutorial page][tutorial].\n\nRequirements\n------------\n\n * Linux, OS X, Windows, or Solaris.\n * `libffi` comes bundled with node-ffi-napi; it does *not* need to be installed on your system.\n * The current version is tested to run on Node 6 and above.\n\nInstallation\n------------\n\nMake sure you've installed all the [necessary build\ntools](https://github.com/TooTallNate/node-gyp#installation) for your platform,\nthen invoke:\n\n``` bash\n$ npm install ffi-napi\n```\n\nSource Install / Manual Compilation\n-----------------------------------\n\nTo compile from source it's easiest to use\n[`node-gyp`](https://github.com/TooTallNate/node-gyp):\n\n``` bash\n$ npm install -g node-gyp\n```\n\nNow you can compile `node-ffi-napi`:\n\n``` bash\n$ git clone git://github.com/node-ffi-napi/node-ffi-napi.git\n$ cd node-ffi\n$ node-gyp rebuild\n```\n\nTypes\n-----\n\nThe types that you specify in function declarations correspond to ref's types\nsystem. So [see its docs][ref-types] for\na reference if you are unfamiliar.\n\nV8 and 64-bit Types\n-------------------\n\nInternally, V8 stores integers that will fit into a 32-bit space in a 32-bit\ninteger, and those that fall outside of this get put into double-precision\nfloating point numbers. This is problematic because FP numbers are imprecise.\nTo get around this, the methods in node-ffi that deal with 64-bit integers return\nstrings and can accept strings as parameters.\n\nCall Overhead\n-------------\n\nThere is non-trivial overhead associated with FFI calls. Comparing a hard-coded\nbinding version of `strtoul()` to an FFI version of `strtoul()` shows that the\nnative hard-coded binding is orders of magnitude faster. So don't just use the\nC version of a function just because it's faster. There's a significant cost in\nFFI calls, so make them worth it.\n\nLicense\n-------\n\nMIT License. See the `LICENSE` file.\n\n[v1apichanges]: https://github.com/node-ffi/node-ffi/wiki/API-changes-from-v0.x-to-v1.x\n[tutorial]: https://github.com/node-ffi/node-ffi/wiki/Node-FFI-Tutorial\n[ref-types]: https://github.com/TooTallNate/ref#built-in-types\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhttptoolkit%2Fnode-ffi-napi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhttptoolkit%2Fnode-ffi-napi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhttptoolkit%2Fnode-ffi-napi/lists"}