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?

有帮助吗?

解决方案

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

其他提示

sudo npm install --global /home/nhaa123/mylib/build/Release/mylib (if that is the folder containing your package.json) documentation: https://npmjs.org/doc/install.html

You don't want to install the module globally – project dependencies are meant to be installed locally (in the project's folder). The only thing you install globally are npm modules meant to be run from the command line.

Instead, just add the path to the folder containing your module (assuming it has its own package.json) to your project's package.json.

{
    "name": "My Project",
    "dependencies": {
        "express": "3.1.x",
        "mylib": "/home/me/mylib"
    }
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top