dependencies vs devDependencies
dependencies are needed when your app runs; devDependencies are only needed while you develop and test.
In this page:
Syntax
npm install package_name
npm install --save-dev package_name
dependencies vs devDependencies
Runtime libraries such as express go in dependencies. Tools like test runners, linters and bundlers go in devDependencies. Production installs with npm install --omit=dev skip the dev group, keeping deployments small.
Note:
If your app crashes in production with cannot find module, a dependency may be wrongly listed as a devDependency.
Example: dependencies vs devDependencies
const pkg = {
dependencies: { express: "^4.19.2", dotenv: "^16.4.5" },
devDependencies: { jest: "^29.7.0", eslint: "^9.0.0" },
};
const prod = Object.keys(pkg.dependencies);
const all = prod.concat(Object.keys(pkg.devDependencies));
console.log("production installs:", prod.join(", "));
console.log("development installs:", all.join(", "));
// Output:
// production installs: express, dotenv
// development installs: express, dotenv, jest, eslint
⚠️ Run this in your own terminal or Node.js environment.
Related Topics
Common Mistakes
- Putting runtime packages in devDependencies
- Putting test tools in dependencies
- Not installing dev dependencies for the build step
Chapter Summary
- dependencies are needed at runtime
- devDependencies are for development
- --omit=dev skips dev packages
- Correct grouping keeps images small
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: