You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 3.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. node-bindings
  2. =============
  3. ### Helper module for loading your native module's `.node` file
  4. This is a helper module for authors of Node.js native addon modules.
  5. It is basically the "swiss army knife" of `require()`ing your native module's
  6. `.node` file.
  7. Throughout the course of Node's native addon history, addons have ended up being
  8. compiled in a variety of different places, depending on which build tool and which
  9. version of node was used. To make matters worse, now the `gyp` build tool can
  10. produce either a __Release__ or __Debug__ build, each being built into different
  11. locations.
  12. This module checks _all_ the possible locations that a native addon would be built
  13. at, and returns the first one that loads successfully.
  14. Installation
  15. ------------
  16. Install with `npm`:
  17. ``` bash
  18. $ npm install --save bindings
  19. ```
  20. Or add it to the `"dependencies"` section of your `package.json` file.
  21. Example
  22. -------
  23. `require()`ing the proper bindings file for the current node version, platform
  24. and architecture is as simple as:
  25. ``` js
  26. var bindings = require('bindings')('binding.node')
  27. // Use your bindings defined in your C files
  28. bindings.your_c_function()
  29. ```
  30. Nice Error Output
  31. -----------------
  32. When the `.node` file could not be loaded, `node-bindings` throws an Error with
  33. a nice error message telling you exactly what was tried. You can also check the
  34. `err.tries` Array property.
  35. ```
  36. Error: Could not load the bindings file. Tried:
  37. → /Users/nrajlich/ref/build/binding.node
  38. → /Users/nrajlich/ref/build/Debug/binding.node
  39. → /Users/nrajlich/ref/build/Release/binding.node
  40. → /Users/nrajlich/ref/out/Debug/binding.node
  41. → /Users/nrajlich/ref/Debug/binding.node
  42. → /Users/nrajlich/ref/out/Release/binding.node
  43. → /Users/nrajlich/ref/Release/binding.node
  44. → /Users/nrajlich/ref/build/default/binding.node
  45. → /Users/nrajlich/ref/compiled/0.8.2/darwin/x64/binding.node
  46. at bindings (/Users/nrajlich/ref/node_modules/bindings/bindings.js:84:13)
  47. at Object.<anonymous> (/Users/nrajlich/ref/lib/ref.js:5:47)
  48. at Module._compile (module.js:449:26)
  49. at Object.Module._extensions..js (module.js:467:10)
  50. at Module.load (module.js:356:32)
  51. at Function.Module._load (module.js:312:12)
  52. ...
  53. ```
  54. The searching for the `.node` file will originate from the first directory in which has a `package.json` file is found.
  55. License
  56. -------
  57. (The MIT License)
  58. Copyright (c) 2012 Nathan Rajlich &lt;nathan@tootallnate.net&gt;
  59. Permission is hereby granted, free of charge, to any person obtaining
  60. a copy of this software and associated documentation files (the
  61. 'Software'), to deal in the Software without restriction, including
  62. without limitation the rights to use, copy, modify, merge, publish,
  63. distribute, sublicense, and/or sell copies of the Software, and to
  64. permit persons to whom the Software is furnished to do so, subject to
  65. the following conditions:
  66. The above copyright notice and this permission notice shall be
  67. included in all copies or substantial portions of the Software.
  68. THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
  69. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  70. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  71. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  72. CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  73. TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  74. SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.