npm
Installation
_$: sudo apt-get install npm
Check
_$: npm config list
; cli configs
user-agent = "npm/3.5.2 node/v4.2.6 linux x64"
; builtin config undefined
globalconfig = "/etc/npmrc"
globalignorefile = "/etc/npmignore"
prefix = "/usr/local"
; node bin location = /usr/bin/nodejs
; cwd = /home/dceresuela
; HOME = /home/dceresuela
; "npm config ls -l" to show all defaults.
The packages will be installed by default in: <prefix>/lib/node_modules
.
Package installation
a) Global
Use this mode for applications that are going to be used from the command line (e.g. gulp
) and must be therefore globally available.
Installation directory: /usr/local/lib/node_modules
_$: npm install <package> --global
_$: npm uninstall <package> --global
b) Local
Use this mode in the general case.
Installation directory: /home/<user>/.../node_modules
_$: npm install <package>
_$: npm uninstall <package>
Configuration file
We can create a package.json
file to track our project’s dependencies.
.../package.json:
-----------------
{
"name": "Test",
"version": "0.0.1"
}
This way, we can save all the packages we have been installing in the local mode as development or production dependencies for our project.
a) Save the installed package as a production dependency:
_$: npm install <package> --save
b) Save the installed package as a development dependency:
_$: npm install <package> --save-dev