NPM:
a third-party package repository (public registry service that contains all packages that programmers publish in NPM),
a third-party package repository (public registry service that contains all packages that programmers publish in NPM),
a way to manage packages installed in your computer,
a standard to define dependencies on other packages
Maintains a centralized repository of public modules (http://search.npmjs.org)
NPM has two modes of operation: global and local (default)
In Global Mode:
NPM installs packages in /usr/local/lib/node_modules
npm install -g <name of the package>
npm install -g sax
NPM will search for, download, and install the latest version of the package named sax inside the directory: /usr/local/lib/node_modules/sax
var sax = require('sax')
Local mode:
NPM installs everything inside the node_modules directory of current working directory
npm install <name of the package>
Installing a specific version of a package
npm install <name of the package>@<version spec>
npm install sax@0.2.5
Resolving dependencies
NPM resolves transitive dependencies.
Updating NPM installed on a machine
Maintains a centralized repository of public modules (http://search.npmjs.org)
NPM has two modes of operation: global and local (default)
a module installed using the local mode will always take precedence
over a module installed globally.
In Global Mode:
NPM installs packages in /usr/local/lib/node_modules
npm install -g <name of the package>
npm install -g sax
NPM will search for, download, and install the latest version of the package named sax inside the directory: /usr/local/lib/node_modules/sax
var sax = require('sax')
Local mode:
NPM installs everything inside the node_modules directory of current working directory
npm install <name of the package>
Installing a specific version of a package
npm install <name of the package>@<version spec>
npm install sax@0.2.5
npm install sax@0.2.x
npm install sax@"<0.3"
npm install sax@">=0.1.0 <0.3.1"
uninstall a module:
npm uninstall <package name>
npm uninstall -g <package name>
Updating a Module:
npm update <package name>
if the package does not exist, it will install it. it exists, gets the latest one
Executable files
When the package is installed locally, executables are stored inside the ./node_modules/.bin directory.Executable files
It’s possible that a module includes one or more executable files.
When the package is installed globally, these executable files are stored in /usr/local/bin
Resolving dependencies
NPM resolves transitive dependencies.
For instance, if you request to install package A and this package depends on
package B and C, Node will fetch packages B and C and install them inside ./node_modules/A/node_modules.
npm install nano
nano depends on
Updating NPM installed on a machine