Node packet manager (npm) is the default package manager for Node. It is used to install, manage, and share JavaScript packages (modules/libraries) for both backend (Node.js) and frontend projects.

Key points:

  • Registry → A large public database of reusable JavaScript packages.
  • CLI Tool → The npm command-line interface is used to install, update, and remove packages.
  • Package Management → Handles versioning, dependencies, and scripts for automation.
  • Configuration File → Uses package.json to define project metadata, dependencies, and scripts.
  • Global vs Local Installs
    • Local: Installed in node_modules inside the project (default).
    • Global: Installed system-wide for command-line tools.

Common commands:

npm init           # Create a new package.json
npm install pkg    # Install a package locally
npm install -g pkg # Install a package globally
npm update pkg     # Update a package
npm uninstall pkg  # Remove a package
npm run <script>   # Run a custom script from package.json