Running npm globally installed packages

There are two ways installing packages: globally and locally.
Locally installed package files end up in your local node_modules (in your project folder where you called npm install some-package).
Globally installed package files end up in your system so they are available in command line, if globally installed packages provides executable then you can invoke it in command line directly some-package(without node), if it does not provide executable then you can use it in repl mode (node) like var package = require('some-package') and it is also available locally (inside your project folder even if you don't have it installed locally).


This started as a comment but got now a little longer.

The problem is not exactly node not finding global packages, node only searches for packages in the current location (like under under node_modules), and that is by design. Globally installed packages can be run from the command like because of the way npm installs them, and this is what makes global packages special in some way.

On Unix based systems, npm creates soft links to the main executables of globally installed packages, like http-server in a folder in the executable path. On my machine, this is /usr/local/bin/. This is why those commands can be invoked from the command line without specifying a full path.

On Windows, npm creates an executable batch file named for instance http-server.cmd under %APPDATA% (typically something like C:\Users\YourUserName\AppData\Roaming). The batch file contains instructions to run the target executable from the location where it's actually installed.