The npm documentation says this:

> 
> * If you’re installing something that you want to use in your program, using
>  require('whatever'), then install it locally, at the root of your project.
> * If you’re installing something that you want to use in your shell, on the command line or 
>  something, install it globally, so that its binaries end up in your PATH environment variable.
> 
> 
> 

I am currently writing --- or, at least, trying to write --- a genuine command line program in node that's intended to be used from the shell. Therefore, according to the above, my dependencies should be installed as global modules.

How do I actually *use* a global module installed with npm in node? Calling `require()` doesn't work, of course, because the npm global module directory (`/usr/local/lib/node_modules`) isn't on the path by default. I can make it working by explicitly adding it to the path at the top of my program, but that's a really lousy solution because it's not portable --- it requires knowledge of where the npm's global module directory is on any given system.

Just to make life even more aggravating, I have some global modules installed via dpkg. These have been put in `/usr/lib/nodejs`, and they just work. This confuses me, because if global modules aren't supposed to be used for ordinary applications I would expect neither to be on the path; or else I would expect them both to be on the path and requiring global modules to just work everywhere. Having one but not the other seems very odd. What's going on here?

**Update:** I should point out that this program is just a script, with `#!/usr/bin/env nodejs` at the top; it's not a formal node module, which is way overkill for something quite this trivial. As the Debian modules are all requireable from such a script, it seems sensible to me that npm's global modules should be requireable too, but I have a feeling that this is a Debianism...
['https://Stackoverflow.com/questions/12585447', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/404568/']
> 
> Therefore, according to the above, my dependencies should be installed as global modules.
> 
> 
> 

Not quite.

It meant that *your module* could be installed as a global so its [binaries](https://npmjs.org/doc/json.html#bin) would be available from the shell:

```sh
npm install -g your-module
your-module-binary --option etc.

```

Its dependencies, on the other hand, should be installed following the 1st point, residing in a `node_modules` directory within your project (generally specified in a [`package.json`](https://npmjs.org/doc/json.html#dependencies) so `npm` can manage them).

But, global modules aren't (normally) available for `require`. They don't follow [Loading from `node_modules` folders](http://nodejs.org/api/modules.html#modules_loading_from_node_modules_folders), which `npm` follows for local modules, and their path isn't typically listed in the `NODE_PATH` variable for [Loading from global folders](http://nodejs.org/api/modules.html#modules_loading_from_the_global_folders).
Additionally, Node.js will search in the following list of GLOBAL\_FOLDERS:

1: $HOME/.node\_modules
2: $HOME/.node\_libraries
3: $PREFIX/lib/node