1. npm (Node Package Manager)
- Comes by default when you install Node.js.
- Used to install packages, manage versions, and run scripts.
🔹 Example: Install React
npm install react
🔹 Install globally:
npm install -g typescript
🔹 Run project scripts (from package.json
):
npm run build
2. npx (Node Package eXecute)
- Comes bundled with npm (v5.2+).
- Lets you run a package without installing it globally.
- Useful for CLI tools you only need occasionally.
🔹 Example: Run create-react-app
without installing it:
npx create-react-app my-app
➡️ This downloads the package temporarily, runs it, then removes it.
3. Yarn
- An alternative to npm, developed by Facebook.
- Faster installs due to caching & parallel downloads.
- Uses
yarn.lock
instead ofpackage-lock.json
.
🔹 Example: Install dependencies
yarn install
🔹 Add a package
yarn add axios
🔹 Run scripts
yarn build
4. pnpm (Performant npm)
- A newer, faster, disk-efficient package manager.
- Uses symlinks and a global store to avoid duplicating dependencies across projects.
- Saves a lot of space compared to npm/yarn.
🔹 Example: Install dependencies
pnpm install
🔹 Add a package
pnpm add lodash
🔹 Run scripts
pnpm run start
Quick Comparison
Tool | Purpose | Key Feature |
---|---|---|
npm | Default package manager | Stable, widely used |
npx | Run packages without install | Temporary execution |
Yarn | Package manager | Faster installs, better caching |
pnpm | Package manager | Efficient disk usage, faster dependency handling |
👉 Example: Installing React in different managers
npm install react
yarn add react
pnpm add react
👉 Example: Running create-react-app
npx create-react-app my-app # No global install