mikemaccana
mikemaccana

Reputation: 123188

NPM: module installation for a command line node tool?

I have a command line tool written in node. I'd like to:

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

Answers (1)

Salman
Salman

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

Related Questions