====== NPM Cheat Sheet ======
| ''npm install'' | Install missing packages. |
| ''npm install package --save'' | Save installed packages to the ''package.json'' file as dependencies. Will be available in all builds, including production. |
| ''npm install package --save-dev'' | Save installed packages to the ''package.json'' file, under the ''devDependencies'' object, as dependencies. Will be available only in dev builds, i.e. not production. |
| ''npm list -g --depth=0'' | List globally installed packages. |
| ''npm uninstall -g [package_name]'' | Uninstall a global package. |
| ''npm outdated'' | List outdated packages. |
| ''npm update'' | This will update the ''package-lock.json'' file but not the ''package.json'' file. |
| ''npm view [package_name]'' | List basic information about a package. |
| ''npm view [package_name] versions --json'' | List version information about a package. |
===== Updating Packages =====
The easiest way is to use the ''npm-check-updates'' package. Yes, that is correct - NPM's update is so bad, you need to use a seperate package to make it work better...
| ''npm install -g npm-check-updates'' | Installs [[https://www.npmjs.com/package/npm-check-updates|npm-check-updates]] |
| ''npm-check-updates'' | Lists what packages are out of date (basically the same thing as running ''npm outdated'') |
| ''npm-check-updates -u'' | Updates all the versions in your ''package.json'' file. |
| ''npm update'' | To install the new versions of your packages based on the updated ''package.json'' file. |
For global packages:
| ''npm-check-updates -g'' (Run as admin) | Lists what global packages are out of date and gives the command to update them. |
===== Versioning =====
| ''^1.2.3'' | Means any ''1.x.y'' version that is equal or higher than ''1.2.3'' and less than ''2.0.0''. |
| ''^0.1.2'' | The leading zero is a special case. Means any ''0.1.x'' version that is equal or higher than ''0.1.2'' and less than ''0.2.0''. |
| ''~2.4.5'' | Patch version only. Means any ''2.4.x'' version that is equal or higher than ''2.4.5'' and less than ''2.5.0''. |