npm — some useful commands

npm

Here unveil some useful npm commands which are useful for our day-to-day work as developers. There are many more than what covered here, but I choose only which are most relevant.

  • npm init → To create a new package.json file with properties like author, description etc.
  • npm init — — yes or npm init — — y→ To create a new package.json file with all properties set to default.
  • npm i → To install all dependency listed in package.json
  • npm i packagename → To install the latest version of a package.
  • npm i -g packagename → To install a package globally, for example, angular cli or react cli.
  • npm i packagename@2.1.0 → To install a specific version of the package.
  • npm i packagename — — save -dev → To install a package as dev dependencies.
  • npm un packagename → To uninstall a package.
  • npm list → To list out all dependency on a project.
  • npm list — — depth=0 → To list out the main dependency or dependency mentioned in the package.json
  • npm view packagename → Details about the package.
  • npm view packagename dependencies → Dependency details of the package.
  • npm view packagename versions →All versions of the package.
  • npm outdated → List out all packages with the latest version if available than we used.
  • npm update → To update the package. This command can be used to update all minor and patch release updates.
  • npm-check-updates → npm-check-updates upgrades your package.json dependencies to the latest versions, ignoring specified versions. More here
  • npm -g outdated → To find out globally outdated packages.
  • npm un -g packagename → To uninstall a global package.
  • npm adduser → This is used when you publish an npm project.
  • npm login → Used to login into npm when you have publish an npm project.
  • npm publish → To publish an npm project.
  • npm version major/minor/patch → To update an npm project.

Note: You may have to add sudo in front of all these commands while using it in MAC OS. For example sudo npm i packagename

Happy Reading!

A <>er

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store