NPM - Node Package Manager
- use nvm, the node version manager, to use several node versions on your machine.
if you want to automatically use a specific node version in a project’s directory, avn might be worth a try.
- use the latest node and npm versions (e.g. node 5.4.1 and npm 3.3.12)
Important npm commands:
npm init: initialize a new npm project. Basically runs an interview tool that writes an initial
npm install: install all npm packages from package.json
npm install my_package_name: install an individual package. Important options:
-gto install a package globally (i.e. not in project’s
node_modules- only used for very few packages)
-Sinstall and add an entry to
dependenciessection (for runtime dependencies)
-Dinstall and add an entry to
devDependenciessection (for compile time dependencies)
npm prune: clean up
node_modules- remove all packages that are no longer listed in
npm shrinkwrap: create an
npm-shrinkwrap.jsonfile that lists all actually installed package versions (much like a Gemfile.lock). More info: What is npm shrinkwrap and when is it needed. N.b.: it will not list devDependencies - you can include them with a command line switch, but presumably this leads to other problems and is not recommended.
Execute an npm package’s binary
- Difference between
^(caret): “In the simplest terms, the tilde matches the most recent minor version (the middle number). ~1.2.3 will match all 1.2.x versions but will miss 1.3.0. The caret, on the other hand, is more relaxed. It will update you to the most recent major version (the first number). ^1.2.3 will match any 1.x.x release including 1.3.0, but will hold off on 2.0.0.” (http://stackoverflow.com/a/22345808)