Below is a sample package.json:
{
"project": "demo",
"version": "1.0",
"prodDeps": { "moduleLib": "1.0" },
"devDeps": { "devTool": "1.0" }
}
Running npm install installs all modules. How can I set it to install only production dependencies by default?
hey, just use npm install --production or set NODE_ENV=production. it skips the dev dependencies and works pretty well in my experience, no need for extra configs
Another approach that has worked well for me is configuring the npm lifecycle scripts to automatically skip dev dependencies. In my projects I adjust the deployment scripts to export NODE_ENV=production so that npm defaults to only installing production modules. This method integrates easily with continuous deployment pipelines, ensuring that the correct dependencies are installed without manual intervention. It’s a reliable solution that has helped streamline the build process and improved overall efficiency on production servers.