3

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

  • Have the app be able to load its dependencies and work. Currently, after npm install -g <somemodule> that module is still not available. Things didn't used to work this way.
  • Not have to run 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?

1 Answer 1

3

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... :)

Sign up to request clarification or add additional context in comments.

3 Comments

Another thing that I interpreted from your question is you want to run the module from any directory, irrespective of where its dependencies are installed. it is correct?
how do i install my module globally from my local repo so I can test it works?
You could npm pack and then do an npm i -g pack.tgz.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.