Dependencies vs DevDependencies
What you'll learn: How to separate packages your app needs to run from tools you only use during development.
The Core Distinction
In package.json, you can list dependencies in two places: dependencies and devDependencies. This separation tells npm (or any package manager) which packages are required for your application to function versus which are only needed during development.
Think of it like this: If you're building a house, dependencies are the bricks, cement, and windows—essential to the house itself. devDependencies are the scaffolding, power tools, and blueprints—critical for building, but you remove them when handing over the finished house.
Runtime vs Build-Time Needs
Dependencies include:
- Libraries your code imports and executes (e.g.,
express,react,lodash) - Packages end users need when running your application
- Installed with
npm install <package>
DevDependencies include:
- Testing frameworks (
jest,mocha) - Bundlers and transpilers (
webpack,babel) - Linters and formatters (
eslint,prettier) - Type checkers (
typescript) - Installed with
npm install <package> --save-devor-D
Installation Behavior
When someone runs npm install in your project, both types install. However, when your package is installed as a dependency of another project, only dependencies are installed—devDependencies are skipped.
In production environments, running npm install --production or npm ci --production installs only dependencies, reducing bundle size and surface area for security vulnerabilities.
Why It Matters
Proper classification keeps production bundles lean, clarifies what your package truly needs, and speeds up CI/CD pipelines. A testing library in dependencies wastes deployment resources; a runtime library in devDependencies causes production crashes.
Key Takeaway: Use dependencies for code your app executes, devDependencies for tools that help you build and test it—npm's installation behavior changes based on this distinction.