How Do You Prevent Install of “devDependencies” npm Modules for node.js (package.json)?
When using npm install
in Node.js, by default, both regular dependencies and devDependencies specified in the package.json
file are installed. If you want to install only production dependencies (excluding devDependencies), you can use the --production
flag.
Here's how you can do it:
npm install --production
This command installs only the dependencies listed in the "dependencies" section of your package.json
file, skipping the packages listed in the "devDependencies" section.
If you want to make this behavior the default for your project, you can set an environment variable:
export NODE_ENV=production
npm install
Or, on Windows:
set NODE_ENV=production
npm install
Setting NODE_ENV
to "production" automatically skips installing devDependencies. This is because npm will assume you are deploying your application in production when NODE_ENV
is set to "production".
Keep in mind that during development, you might still need to install devDependencies. If you switch back to development mode, ensure to unset or change NODE_ENV
accordingly.
It's also worth noting that some tools and scripts may rely on packages listed in devDependencies even during development, so be cautious about excluding them in certain situations.
-
Debugging Node.js Memory Leaks
Learn about Node.js memory leaks and their causes, how to debug and fix them, prevention best practices, methods for monitoring leaks.
Guides -
Using Node.js require vs. ES6 import/export
Node.js uses CommonJS-style require for module loading, while ES6 introduces a native import and export syntax. Each has its own style and use cases. Using require (CommonJS): // Importing a module...
Questions
Make your mark
Join the writer's program
Are you a developer and love writing and sharing your knowledge with the world? Join our guest writing program and get paid for writing amazing technical guides. We'll get them to the right readers that will appreciate them.
Write for usBuild on top of Better Stack
Write a script, app or project on top of Better Stack and share it with the world. Make a public repository and share it with us at our email.
community@betterstack.comor submit a pull request and help us build better products for everyone.
See the full list of amazing projects on github