Course contentsShow
← JavaScript
Lesson 2497 of 2,72351. Package ManagementFree lesson

Understanding package.json Dependencies

Learn the difference between dependencies, devDependencies, and peerDependencies fields in package.json.

Understanding package.json Dependencies

What you'll learn: How to properly categorize your project's packages using dependencies, devDependencies, and peerDependencies in package.json.

The Three Types of Dependencies

When you run npm install, you're adding packages to your project—but where they belong in package.json matters. Think of it like organizing tools in a workshop: some you need to build the product, some you only need during construction, and some you expect the customer to already own.

dependencies

These are packages your application needs to run in production. When someone installs your package or deploys your app, these dependencies come along for the ride.

"dependencies": {
  "express": "^4.18.0",
  "lodash": "^4.17.21"
}

If your code imports and uses it at runtime, it belongs here.

devDependencies

These packages are only needed during development—testing frameworks, build tools, linters. They won't be installed when someone uses your published package or in production environments using npm ci --production.

"devDependencies": {
  "jest": "^29.0.0",
  "eslint": "^8.0.0"
}

Install with: npm install --save-dev packagename

peerDependencies

This signals "I'm designed to work with this other package, but you should install it." Common for plugins and extensions. For example, a React component library doesn't bundle React itself—it expects the host project to provide it.

"peerDependencies": {
  "react": "^18.0.0"
}

This prevents duplicate installations and version conflicts.

Why It Matters

Proper categorization keeps production bundles lean, makes installation faster, and prevents compatibility issues. Putting everything in dependencies bloats your deployment; putting runtime needs in devDependencies breaks production.

Key Takeaway: Use dependencies for runtime code, devDependencies for build/test tools, and peerDependencies for packages the consumer should provide.