NPM, an acronym for node package manager is a tool that is used to install, uninstall & publish the Node.JS package. Nowadays, Node.JS packages are not only used for node relate project but also used for tooling to other non-node related projects. So I am creating this post where you will find cheatsheet of important NPM command for quick reference.
Install, update & Uninstall
Description
Command
install all package mentioned in 'package.json'
npm install
install package 'express'
npm install express
install package 'express' globally
npm install express -g
install package 'express' with version '3.0.0'
npm install express@3.0.0
install package 'express' & save it as dependency in 'package.json'
npm install express --save
install package 'express' & save its exact version as dependency in 'package.json'
npm install express --save --save-exact
install package 'express' & save it as optional-dependency in 'package.json'
npm install express --save-optional
install package 'express' & save it as dev-dependency in 'package.json'
npm install express --save-dev
show debug log while installing package 'express'
npm install express -d
uninstall package 'express'
npm uninstall express
uninstall package 'express' & remove it from depenedency in 'package.json'
npm uninstall express --save
uninstall package 'express' & remove it from dev-depenedency in 'package.json'
npm uninstall express --save-dev
uninstall package 'express' & remove it from optinal-depenedency in 'package.json'
npm uninstall express --save-optional
check if any package in 'package.json' is outdated
npm outdated
update all packages in 'package.json'
npm update
update specific package 'express' in 'package.json'
npm update express
update all packages & its version in 'package.json'
npm update --save
Config
Description
Command
list current setting
npm config list
set key=value in npm config
npm config set key value
set proxy url
npm config set proxy PROXY_URL
get the value of key 'proxy'
npm config get proxy
delete the value of key 'proxy'
npm config delete proxy
open editor(system default) to edit npm config file
npm config edit
set cache timeout for package, to install offline
npm config set cache-min 9999999
Others
Description
Command
Intialize any folder with 'package.json'
npm init
run script with name 'start'
npm start
run script with name 'build'
npm run build
npm cache folder on linux & windows
~/.npm%AppData%/npm-cache
delete all data from cache folder
npm cache clean --force
create an user with npm so that we can login to publish package
npm adduser
login to npm, so that you can publish package
npm login
publish package to npm registry
npm publish
publish scoped package as public, by default private
npm publish --access=public
unpublish package from npm registry
npm unpublish
update version before re-publishing updated package
npm version [patch/minor/major]
If you loved this post, Please share it on social media.