Skip to content

Instantly share code, notes, and snippets.

@pmayur
Last active January 2, 2021 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pmayur/2f8d3f60f993a79e80b34b7eb01d01e6 to your computer and use it in GitHub Desktop.
Save pmayur/2f8d3f60f993a79e80b34b7eb01d01e6 to your computer and use it in GitHub Desktop.
NPM - Sameer Buna

Install package from the github repository

Installs directly from the latest version of the repository upto the latest commit

npm i <package-name>/<repo-name>

npm i express/express

Install without actually installing

Would not actually install express but would report on the version that would be installed with the command

npm i --dry-run <package-name>

npm i --dry-run express

View dependency tree or dependency tree with info

list names of all packages and view names with description of all packages

npm ls
npm ll

-g --depth=0 --json
  • -g list all globally installed packages with dependency sub-tree for every package
  • --depth=0) levels of trees,0 = only 1st level, 1 = first child etc
  • --json shows the output in json format

flags while installing dependencies

-S / -s - production
-D / -d - development
-O / -o - optional (used only if installed)

Check for outdated packages

can be used with -g flag for global

npm outdated 

Change configuration for npm

  • lists all options that can be changed
npm config list -l
  • default values can be set using
npm config set <variable-to-be-set> "<string-value>"

eg: npm config set init-author-name "John Doe"
  • values can be removed as well
npm config delete <variable-to-delete>
  • all installs will have -s flag everytime, is by default true
npm config save true
  • searches for the word in the package tree
npm search <word>
  • locks dependecies, versioning won't help, always the locked versions will be installed
npm shrinkwrap
  • opens the home page or repository for the package in the default browser
npm home <package-name>
npm repo <package-name>
  • removes packages installed without mention in package.json
npm prune
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment