NPM package managment
Install package via NPM
npm install <modulename> --save
npm install <modulename>@<version> --save
# install globally :
npm install --global <modulename>
Install dev package via NPM
npm install <modulename> --save-dev
Add default '--save' to config
npm config set save true
Install package from git repo
npm install git://github.com/my/dep.git
Uninstall package
npm uninstall <module_name>
NPM project initialization
npm init
NPM configuration
get configuration
npm config ls -l
npm config list
npm config get <conf-key>
edit configuration
npm config set <conf-key>=value
npm config edit
npm config set proxy=proxy.dns.fr:3128
npm config set https-proxy=proxy.dns.fr:3128
Update global version
npm update npm -g
NPM scripts
<package.json>
"scripts" : {"the-script" : "node testfile.js"}
Run known or custom script :
npm test
npm run my-custom-script
- prepublish, publish, postpublish
Run while the package is published
- preinstall, install, postinstall
Run while the package is installed
- preuninstall, uninstall, postuninstall
Run while the package is uninstalled
- prestop, stop, poststop
Run by the npm stop command
- pretest, test, posttest
Run by the npm test command
- prestart, start, poststart
Run by the npm start command
- prerestart, restart, postrestart
Run by the npm restart command (if no 'restart' script, run 'stop' and 'start')
Publish
npm adduser [--registy=<registry>]
npm login [--registy=<registry>]
npm publish [--registy=<registry>]