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?
sudo npm install --global /home/nhaa123/mylib/build/Release/mylib
(如果这是包含package.json的文件夹)文档: https : //npmjs.org/doc/install.html
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:
main
in https://npmjs.org/doc/json.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"
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.