NPM common commands cheatsheet.

# install package with options to update package.json
npm i[nstall]
-S/—save     (dependencies in package.json)
-D/—save-dev (devDependencies in package.json)
-G/—global (install to globally shared location)

# install package with specific version
npm i name@1.2.0

# shortcut commands
npm un[install]
npm up[date]

# list available scripts
npm run

# update npm itself
npm install -g npm@latest

# list globally installed packages
npm list -g --depth=0
# list locally installed packages (node_modules)
npm list
npm ls
npm ls --prod

# install from Github
npm i username/repo
npm i username/repo#branch
# install from Bitbucket/Gitlab
npm i bitbucket:username/repo
npm i gitlab:username/repo

# go to package repo
npm repo <name>
# go to package home
npm home <name>
# go to package docs
npm docs <name>

# view package info
npm view <name> <property-in-json>
# search package
npm search <name>

# print the bin folder
npm bin
npm bin -g

# print the root folder
npm root
npm root -g

# create package.json with preset
npm init
npm init --scope=scop-name

# bump version in package.json
npm version x.x.x

# login to npm registery
npm login

# package local package
npm pack

# publish package
npm publish
npm publish --access=public

# start default server.js in root
npm start (node server.js)
TOP▲
Post tagged with: npm