Skip to content

Instantly share code, notes, and snippets.

@helephant
Last active May 17, 2019 19:02
Show Gist options
  • Save helephant/e155ac2b29c29b4ae872f4355623e93f to your computer and use it in GitHub Desktop.
Save helephant/e155ac2b29c29b4ae872f4355623e93f to your computer and use it in GitHub Desktop.

NPM command cheat sheet

Instantiate NPM in the current directory

npm init

Installing a new package.

npm install package-name
npm install package-name@version
npm install package-name@latest

Installing a package only for development.

npm install --save-dev package-name

Removing a package.

npm uninstall package-name

Finding details of a package like description, maintainers, versions and dependencies.

npm show package-name

List all packages installed into the current directory.

npm ls

Running console commands that were installed through npm.

npx command-name

Running build steps defined in NPM.

npm start
npm test
npm run my-run-step
npm help npm-scripts

Updating packages

Listing all packages that need updating.

npm outdated

Finding the version of a package

npm view package version

Update all packages that need updating.

npm update

Semantic versioning:

  • Exact version: 3.3.1 or =3.3.1
  • At least minor version: ^3.3.1
  • Any minor version: 3.*
  • At least patch: ~3.3.1
  • Any patch: 3.3.*

Publishing a package

Publish a new version of a package.

npm login
npm publish
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment