Runtime Dependencies (`dependencies`)
Guide to runtime dependencies in Node.js, when to install packages into dependencies, dependency resolution, and bundle size considerations.
The dependencies field in package.json specifies third-party packages strictly required for the application to run in production environments.
When to Put a Package in dependencies
Ask yourself: "Will this code execute when the app is running in production?"
-
✅ Yes $\rightarrow$
dependencies:- Web frameworks (
express,fastify,hono,next) - Utility libraries imported in runtime code (
lodash,date-fns,zod,axios) - Database drivers and ORMs (
pg,@prisma/client,drizzle-orm) - State management (
zustand,redux-toolkit)
- Web frameworks (
-
❌ No $\rightarrow$
devDependencies:- Compilers and type checkers (
typescript,@types/*,babel) - Bundlers and build tools (
esbuild,vite,webpack) - Testing frameworks (
vitest,jest,playwright) - Linters and formatters (
eslint,prettier)
- Compilers and type checkers (
Installing Dependencies
# npm (default saves to dependencies)
npm install zod
# pnpm
pnpm add zod
# Explicit save flag
npm install --save-prod axiosProduction Impact & Bundle Size
In server environments, production deployments strip devDependencies using npm ci --omit=dev to reduce memory and startup overhead.
In client-side frontend applications (React/Next.js/Vite), modern bundlers perform Tree Shaking to eliminate dead code. However, heavy dependencies still increase client bundle size.
[!TIP] Use tools like
bundlephobia.comorbundle-analyzerto inspect package weight before installing new dependencies.
Related Guides
Understanding package.json
Complete field-by-field reference for package.json, including name, version, main, module, exports, type, scripts, dependencies, engines, and workspaces.
Development Dependencies (`devDependencies`)
Guide to devDependencies in package.json, why separating dev tools matters, how production builders prune devDependencies, and install commands.