Reputation: 123188
I have a command line tool written in node. I'd like to:
npm install -g <somemodule>
that module is still not available. Things didn't used to work this way.npm link
on every folder, as I have read in the NPM 1.0 docs. The above docs also talks about $PATH, which seems unrelated to the topic as I care about node modules, not binaries.How can/should a node command line tool handle its dependencies so that the command line tool can run from any directory?
Upvotes: 3
Views: 636
Reputation: 9447
You can add following in the main file of your node.js app, assuming your file name is node-binary.js
.
#! /usr/bin/env node
// your app code
console.log('TEST node binary');
And, in package.json file you need to specify which is the entry point of your app
...
"preferGlobal": "true",
"bin": {
"node-binary": "node-binary.js"
},
...
and run the command npm link
in the app directory. You should now be able to use node-binary
command from any directory.
Hope that helps... :)
Upvotes: 3