How npm detects which node packages are installed on a Windows machine?

I wonder if there is an explanation somewhere (maybe on node js website) about the next situation related to packages:

  • I installed a sample application, let's say in d:\samples\backbone directory, meaning that also the node packages were created there.

  • Listing the installed packages with npm list from command line in d:\samples\backbone\option2 directory will show me the installed packages, the same if I run in d:\samples\backbone. If running in d:\samples directory, the packages are not shown anymore.

I guess that node searches for installed packages in all directories up to the root, but is somewhere in docs mentioned about it?

Any globally installed modules (for exmaple: npm install -g express) are installed in C:\Program Files (x86)\nodejs\node_modules

Anything that has been locally installed (such as async, mysql), is placed in your directory inside a ./node_modules/ folder.

In this case, your backbone app has local dependancies, so its packages are installed locally inside d:\samples\backbone\node_modules

If you look at Node.js' documentation, on the modules page - http://nodejs.org/api/modules.html - take a look at the sections:

  • Core Modules
  • File Modules
  • Loading from node_modules Folders

You'll find how require() is resolved.