Package Managers Basics
8 examples to get you started with Package Managers - 6 basic and 2 intermediate.
Search across all documentation pages
8 examples to get you started with Package Managers - 6 basic and 2 intermediate.
mkdir my-api && cd my-api && npm init -y.Add a production dependency and record the exact resolved version in package-lock.json.
npm install express@5npm install <pkg> writes to dependencies and updates package-lock.json.package.json when you need predictable upgrades.Related: Lockfiles & Reproducible Installs - CI-safe installs
Keep build-time tools out of production bundles by using --save-dev.
npm install --save-dev typescript@5.6NODE_ENV=production and you run npm ci --omit=dev.devDependencies for backend services compiled at build time.package.json; let the lockfile pin the patch.Related: package.json Scripts - wire
buildandtypecheckscripts
Execute CLIs without polluting package.json using npx.
npx --yes tsx src/index.tsnpx downloads to a cache, runs the binary, and exits.--yes skips the install prompt in CI and scripts.Surface drift between package.json ranges and the registry.
npm outdatednpm audit for security fixes.npm update on Friday afternoon without a test run.Related: Supply Chain: npm audit & Socket - gate risky upgrades
pnpm stores packages once on disk and links them into each project via a content-addressable store.
corepack enable
corepack prepare pnpm@latest --activate
pnpm init
pnpm add fastify@5lodash.node_modules/.pnpm layout is stricter; phantom dependencies are harder to rely on accidentally.corepack so CI and laptops use the same pnpm version.Related: Workspaces & Monorepos -
workspace:*protocol
Yarn Modern (v4) supports Plug'n'Play and optional checked-in caches for fast CI.
corepack enable
yarn init -2
yarn add zodyarn install in CI.Reject installs on unsupported Node versions before runtime surprises.
{
"engines": {
"node": ">=24.18.0 <25"
}
}# .npmrc at repo root
engine-strict=trueengines documents the supported runtime; engine-strict makes npm fail on mismatch.node --version and npm ci.Related: engines & engine-strict - local and CI enforcement
Decision matrix for backend TypeScript services.
| Manager | Choose when | Skip when |
|---|---|---|
| npm | Default choice, single-service repos, minimal tooling | Massive monorepos where install time dominates |
| pnpm | Monorepos, disk/CI cache pressure, strict dependency graph | Team unwilling to fix phantom-import assumptions |
| Yarn Berry | Zero-install workflow, PnP benefits understood | Mixed ecosystem expecting Classic node_modules layout |
Related: Package Managers Best Practices - one lockfile policy
Stack versions: This page was written for Node.js 24.18.0 (Active LTS), npm 10+, TypeScript 5.6+, Express 5, Fastify 5, and NestJS 11.
Reviewed by Chris St. John·Last updated Jul 18, 2026