NPM - Node Package Manager : npm makes it easy for JavaScript developers to share and reuse code, and it makes it easy to update the code that you’re sharing.
The official documention is available at : http://docs.npmjs.com
https://www.npmjs.org - centralized repository of public modules
global / local - Node modules can be installed locally or globally. Global installation of modules makes them available throughout any NodeJS Application you are writing on the same system. Local installation includes the module files into the same working directory and makes them available to your application (in the working directory). Default mode of operation is local -> doesn’t make system wide changes - always use the default local mode if you are in a doubt
All packages will be installed into /usr/local/lib/node_modules, uses –g flag for Global mode. For example:
npm install -g sax
in any script file, you can then use sax module by using var sax = require(‘sax’);
default mode, downloads the modules into node_modules directory of your current working directory. For example:
npm install sax
npm install sax@0.2.5 // will install a 0.2.5 version npm install sax@0.2.x // installs the latest release of the 0.2 branch npm install sax@“<0.3” // latest version before 0.3 npm install sax@“>=0.1.0 <0.3.1” // more complicated requirements
npm uninstall // removes a module locally npm -g uninstall // removes a module globally
npm update // updates an installed module, if the package was not installed the command will install it npm update -g // update a globally installed module
Basically this can be considered as an alternative to composer.
package.json can be use this one to define the dependencies, which will be then installed by executing the following command in your working directory:
npm install
example of using package.json:
{ “name” : “MyApp”, “version” : “1.0.0”, “dependencies” : { “sax” : “0.3.x”, “nano” : “*", “request” : “>0.2.0” } }