IT:AD:npm:HowTo:Define the Local Root Folder
Summary
Packages can be installed locally or globally.
If you want: * to use it as a command line tool, then you want to install it globally.
- eg: grunt CLI, tidyhtml
* to depend on the package from your own module using something like Node's require, then you want to install locally.
- eg: …
If you don't add a -g global flag, NPM installs packages to locally, to the local root folder.
The local root folder is discovered by NPM recursing upwards from the current directory, until it finds a folder with package.json in it.
If there is no parent directory that has a packages.json file in it, it will choose the current directory (this, and the warning given below is why it is recommended that npm init is invoked earlier than diving in unprepared).
package.json in the current directory - so if a later project makes a package.json in a parent directory (by mistake, by intent, whatever the reason) you may find new packages not being downloaded to the directory you intended (they'll be installed in the parent directory where the other project's package.json exists.
Hence why you should create a package.json file first: * IT:AD:NPM:HowTo:Create a package.json File
- create a package.json file first
npm init
Once the app knows where to install
- install something.txt
npm install gulp
Process
In case you want to check via a IT:AD:CLI where the root folder is:
- where is the root.txt
npm root