Simple native module bindings (.node) ESM loader with prebuild support

Usage no npm install needed!

<script type="module">
  import nodeGypLoad from '';



Very simple native module bindings (.node) ESM loader with prebuild support.

Because already existing solutions are either

  • too complex
  • involve 3rd party remote download location
  • do not support specifying bindings name (multiple targets in binding.gyp)

⚠️ You are probably better off using the battle-tested already existing solutions. This was for a very specific need and experimenting with package.json "bin" property.


Find/Load bindings

import { find, load } from "node-gyp-load";
import { join, dirname } from "node:path";
import { fileURLToPath } from "node:url";

const bindings = await find({
  name: "target_name", //node-gyp target name (without ext ".node")
  dir: join(dirname(fileURLToPath(import.meta.url)),"../"), //root dir where to search. (default to ".") 
  prebuild: true //search the folder "prebuilds" (see below for more details)

const nativeModule = load(bindings);
const { someFn, someFn2 } = load(bindings);



Add node-gyp-load as an install script to your native project

  "scripts": {
    "install": "node-gyp-load"

Prebuild(s) are expected to be found in the prebuilds folder.
Organized in subfolders "platform-arch"
Filename should end with ".napi.node".
And as the name suggests be a n-api native addon.



Install script will check for prebuild(s) before building your project with node-gyp rebuild. But you can force compile by doing npm install --build-from-source


⚠️ This module is only available as an ECMAScript module (ESM).

Named export

find(option?: obj): Promise<string>

Find your native module's .node file (bindings).


option type default description
name string "bindings" .node filename (node-gyp target name)
dir string "." root dir where to search
prebuild bool true search the "prebuilds" folder or not

load(bindings: string): any

Load given bindings path.