Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Helper module for loading your native module's bindings in a cross-platform way
The 'bindings' npm package is a utility that helps load compiled bindings for Node.js addons. It simplifies the process of including and distributing native C++ addons with Node.js modules by resolving the path to the compiled binary based on the current platform, architecture, and module version.
Loading compiled bindings
This code demonstrates how to load a compiled Node.js addon using the 'bindings' package. The 'bindings' function is called with the name of the addon, and it returns the loaded module.
const bindings = require('bindings');
const addon = bindings('addon');
node-gyp is a cross-platform command-line tool written in Node.js for compiling native addon modules for Node.js. It is similar to 'bindings' in that it deals with native addons, but node-gyp focuses on the build process, whereas 'bindings' focuses on loading the compiled binaries.
node-pre-gyp is a tool that provides a way to publish and install Node.js C++ addons from binaries. It is similar to 'bindings' as it helps in managing native addon modules, but node-pre-gyp focuses on the installation of pre-compiled binaries, potentially avoiding the need for a build toolchain on the installing machine.
ffi-napi is a Node.js addon for loading and calling dynamic libraries using pure JavaScript. It is similar to 'bindings' in that it allows interaction with native code, but ffi-napi uses foreign function interfaces to directly call into dynamic libraries, bypassing the need for compiled bindings.
nan (Native Abstractions for Node.js) is a header file that wraps V8 and Node.js APIs, providing a set of tools for developing native addons. While 'bindings' helps in loading compiled modules, nan helps in writing the C++ code that is compatible with different versions of Node.js and V8.
This is a helper module for authors of Node.js native addon modules. In node >= 0.7.0, it is encouraged to statically precompile your native addons for your various supported platforms and architectures, rather than depend on your users to do that. This adds two new burdens on the developer that we now need to condider while writing our module:
node-bindings
attempts to solve probelm #2
.
This module solves the organizational problem of how to store these bindings files with a simple directory convention:
<module_root>/compiled/<node_version>/<platform>/<arch>/bindings.node
So for example, on a 32-bit Windows platform, running node v0.6.9
, the
bindings.node
file should be placed in:
<module_root>/compiled/0.6/win32/ia32/bindings.node
On 64-bit Mac OS X, running node v0.7.1-pre
, then the bindings file should be
placed in:
<module_root>/compiled/0.7/darwin/x64/bindings.node
For reference, the calculations for the various parts that makes up the require path are:
<module_root>
- The directory where package.json
is found is the root.<platform>
- process.platform
<arch>
- process.arch
<node_version>
- parseFloat(process.versions.node)
The default "compiled" directory is compiled
and the default name of every
"bindings" file is bindings.node
. This is configurable if you'd like.
Install with npm
:
$ npm install bindings
require()
ing the proper bindings file for the given platform and architecture
and node version is as simple as:
var bindings = require('bindings')()
// Use your bindings defined in your C files
bindings.your_c_function()
You can specify the name of the bindings file if you desire:
var bindings = require('bindings')('my_bindings.node')
Or you can pass in an options Object for full configuration:
var bindings = require('bindings')({
bindings: 'my_bindings.node'
, compiled: 'builddir'
})
Error: Could not load the bindings file. Tried:
↳ /Users/nrajlich/node-ffi/out/Debug/ffi_bindings.node
↳ /Users/nrajlich/node-ffi/Debug/ffi_bindings.node
↳ /Users/nrajlich/node-ffi/out/Release/ffi_bindings.node
↳ /Users/nrajlich/node-ffi/Release/ffi_bindings.node
↳ /Users/nrajlich/node-ffi/compiled/0.6/darwin/x64/ffi_bindings.node
at bindings (/Users/nrajlich/node-bindings/bindings.js:69:13)
at Object.<anonymous> (/Users/nrajlich/node-ffi/lib/ffi.js:3:34)
at Module._compile (module.js:444:26)
at Object..js (module.js:462:10)
at Module.load (module.js:351:31)
...
(The MIT License)
Copyright (c) 2012 Nathan Rajlich <nathan@tootallnate.net>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
FAQs
Helper module for loading your native module's .node file
The npm package bindings receives a total of 6,430,793 weekly downloads. As such, bindings popularity was classified as popular.
We found that bindings demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.