What is node-pre-gyp?
The node-pre-gyp package is a tool that allows developers to publish and install Node.js native add-ons from binaries. This eliminates the need for developers to compile their native add-ons from source during installation, simplifying the deployment process and reducing setup time.
What are node-pre-gyp's main functionalities?
Publishing binaries
This command allows developers to publish pre-compiled binary files to a hosting service, making them available for installation. This is useful for distributing Node.js native add-ons without requiring users to compile the code themselves.
node-pre-gyp publish
Installing binaries
This command facilitates the installation of pre-compiled binaries from a remote source. It checks for compatible binaries and downloads them, which speeds up the installation process by avoiding the need for compilation.
node-pre-gyp install
Rebuilding binaries
This command is used to rebuild the native add-on binaries from source. It is useful when pre-compiled binaries are not available or when custom modifications to the binary are needed.
node-pre-gyp rebuild
Other packages similar to node-pre-gyp
node-gyp
node-gyp is a cross-platform command-line tool written in Node.js for compiling native addon modules for Node.js. It provides a similar functionality to node-pre-gyp but requires compilation from source, unlike node-pre-gyp which can download pre-compiled binaries.
prebuild
prebuild is a tool that helps in prebuilding native modules for Node.js. Similar to node-pre-gyp, it supports the installation of pre-compiled binaries. However, prebuild often works in conjunction with prebuild-install and offers a slightly different workflow for managing binary deployments.
prebuildify
prebuildify focuses on creating local prebuilds for native Node.js modules. Unlike node-pre-gyp, which can download binaries from a remote location, prebuildify is designed for bundling the binaries directly with the module, which can be useful for applications that need to work offline or have restricted network access.
node-pre-gyp
Node.js native add-on binary install tool.
- Stands in front of node-gyp
- Installs your module from a pre-compiled binary (which you are responsible for hosting)
- If successfull avoids needing node-gyp to be invoked.
- Falls back to calling
node-gyp rebuild
if binaries are not available
EXPERIMENTAL - not ready for widespread use.
Design
You add a binary
property to your package.json
which lists:
module_name
: The name of your native node module.module_path
: The location your native module is placed after a build (commonly build/Release/
)remote_uri
: A url to the remote location where tarball binaries are availabletemplate
: A versioning string which describes the tarball versioning scheme for your binaries
And example from node-osmium
looks like:
"binary": {
"module_name": "osmium",
"module_path": "./lib",
"remote_uri": "http://node-osmium.s3.amazonaws.com",
"template": "{module_name}-v{major}.{minor}.{patch}-{node_abi}-{platform}-{arch}.tar.gz"
},
Then to package a binary you do:
mkdir stage
node-pre-gyp publish
Then post the resulting tarball (in the stage/
directory) to your remote location.
Finally you add a custom install
script:
"scripts": {
"install": "node-pre-gyp rebuild",
}
Then users installing your module will get your binary, if available, instead of a source compile.
Modules using node-pre-gyp
: