npm — Explained with Examples
npm (Node Package Manager) installs and manages JavaScript dependencies from a registry, defining projects with package.json and node_modules.
npm is the default package manager for Node.js. It installs packages from the npm registry into a node_modules directory, tracks dependencies in package.json, and generates package-lock.json for reproducible installs. npm also provides a scripting system (npm run build, npm test) for common tasks.
Think of npm like an app store for code. You search for packages (apps), install them with one command, and your project’s package.json acts like a shopping list — anyone who clones your project can install everything at once.
Dependencies are categorized as dependencies (runtime), devDependencies (build tools), and peerDependencies (shared requirements). The lockfile ensures consistent versions across environments.
# Initialize a new project
npm init -y
# Install a dependency
npm install express
# Install a dev dependency
npm install --save-dev typescript
# Run a script
npm run buildnpm supports workspaces for monorepos, scoped packages (@scope/package), and scripts for automating tasks. Alternatives include Yarn and pnpm.
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro