Search code examples
node.jsnode-gyp

How to install customer node.js binary module globally?


So I've made my own module with C++ and node-gyp. Things go fine after node-gyp configure build and I've got under build/Release everything I need.

Now, in my other project where I'm using this module, I don't want to add it like

var a = require('../../mylib/build/Release/mylib');

but instead

var a = require('mylib');

after defining dependencies in package.json. So how do I use npm or something else to achieve this?


Solution

  • You can add the entry point to your package to the main field in your package.json. This is what will be called when you do require('yourpackage').

    See these links:

    1. at end of section 8.1 http://book.mixu.net/node/ch8.html
    2. under section main in https://npmjs.org/doc/json.html