← Back to Node.js Course | Chapter 3: npm & Packages | Lesson 3 of 7

dependencies vs devDependencies

dependencies are needed when your app runs; devDependencies are only needed while you develop and test.
Syntax
javascript
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

javascript
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/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
Common Mistakes
  1. Putting runtime packages in devDependencies
  2. Putting test tools in dependencies
  3. 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:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.