I am not happy with the official npm documentation as I never find quickly what I am looking for. So I decided to write a short npm cheat sheet with the most often commands I use.
Get npm help
npm -h
or npm -h
Generate package.json in a module directory, based on npm parameters.
npm init
npm init -y
(accept all default answers)
Install a package and also update package.json with the installed version and package name.
npm install --save
npm install @1.8.2 --save --save-exact
(specific version)
Install a package and also update package.json with the installed version and package name, but into the devDependencies section.
npm install --save-dev
Uninstall package (A nice thing about npm is you can always just rm -rf ./node_modules/
)
npm uninstall --save
List installed packages with dependency tree depth of zero.
npm ls --depth 0
List outdated libraries compared to currently installed node_modules.
npm outdated
Update dependencies.
npm update
npm update --prod
(only prod dependencies)
npm update --dev
(only dev dependencies)
List all npm configuration flags.
npm config ls -l
Setting, getting and deleting defaults.
npm set 'value'
npm get
npm config delete
Update the global npm version.
npm update npm -g
(run this command with admin privileges)
⇒ Note that this is not working under windows. The best way to update npm is to install npm-windows-upgrade and do the update with this tool.
npm install -g npm-windows-upgrade
npm-windows-upgrade
npm shortcuts.
https://docs.npmjs.com/misc/config#shorthands-and-other-cli-niceties