Hi, I'm Jacob. Enjoying devFlipCards? Buy me a coffee

52. How do you install packages locally and globally using npm?

npm allows installing packages both locally (for a specific project) and globally (for the entire system).

Local installation:

  • Command:
npm install <package-name>
  • Description: Packages are installed in the project's node_modules directory and are only available for that project. Dependencies are recorded in the package.json file under dependencies.

Example:

npm install express

Global installation:

  • Command:
npm install -g <package-name>
  • Description: Packages are installed globally and are available from anywhere in the system. Global installation is mainly used for command-line tools like webpack, gulp, etc.

Example:

npm install -g webpack

Managing local and global packages:

  • List locally installed packages:
npm list
  • List globally installed packages:
npm list -g --depth=0
  • Uninstall a package locally:
npm uninstall <package-name>
  • Uninstall a package globally:
npm uninstall -g <package-name>

Installing packages locally and globally using npm allows for flexible management of project dependencies and development tools.

Struggling to find common date to meet with your friends? Try our new tool
commondate.xyz