dependencies vs devDependencies in package.json
understanding runtime versus build/test tooling.
dependencies ship and run in production; devDependencies are only for development; omitted with npm install --production.
WHAT THIS TESTS This checks whether you understand the lifecycle distinction between code that runs in production and tooling that only supports development. It also touches on lean, secure deployments.
A GOOD ANSWER COVERS Entries under dependencies are required for the application to execute at runtime and are installed in every environment, including production. Entries under devDependencies are needed only while developing, building, or testing, and are excluded when you install with the production flag or when NODE_ENV is production. npm install --save adds to dependencies and --save-dev adds to devDependencies. Getting this right shrinks production node_modules, speeds installs, and reduces the surface area for vulnerabilities.
COMMON WRONG ANSWERS Saying the distinction is purely cosmetic, or that npm ignores it. Misclassifying, such as putting jest, eslint, nodemon, or typescript types in dependencies, or placing a runtime library that your source imports, like express or axios, in devDependencies, which causes module-not-found errors after a production install.
LIKELY FOLLOW-UPS What peerDependencies and optionalDependencies are for, how transitive dependencies are still installed regardless of category, and why a compiler like the TypeScript compiler is a devDependency even though the app needs its output.
ONE CONCRETE EXAMPLE For a web service, express belongs in dependencies because the running server imports it on every request. jest belongs in devDependencies because it only runs your test suite locally and in CI and never executes in production. If you build a production Docker image with an install that drops devDependencies, express must still be present, so it has to be a regular dependency.
Read the original → docs.npmjs.com
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.