I’m working on a Node.js project and need help with npm dependency management. Here’s my current package.json setup:
{
"name": "my-project",
"version": "1.0.0",
"dependencies": {
"express": "^4.18.0"
},
"devDependencies": {
"nodemon": "^2.0.15"
}
}
I’m running NPM version 1.1.1 on macOS 10.6.8. The issue is that when I execute:
npm install
It installs both regular dependencies and devDependencies. I thought this command was supposed to install only devDependencies:
npm install --dev
What I need is a way to make npm install
install only the production dependencies, while having a separate command that installs everything including development dependencies. How can I achieve this behavior for production deployments?
set NODE_ENV=production before you run npm install - that way it skips devDeps. but ur npm version (1.1.1) is really old lol. upgrading will help, but the production flag is still good even on older versions.
That’s actually how npm install is supposed to work - it always grabs both production and dev dependencies. For production deployments, use npm ci --only=production
instead. The ci command is faster and more reliable since it installs straight from package-lock.json without touching it. Newer npm versions also support npm install --omit=dev
if you want an alternative to the --production flag. Your npm 1.1.1 is pretty outdated though - upgrading would give you better performance and more dependency management options.
That’s just how npm works by default. When you run npm install
, it installs both dependencies and devDependencies. There’s no --dev
flag - you’re probably thinking of --only=dev
, which installs only devDependencies. For production, use npm install --only=production
or npm install --production
. This installs only the packages under dependencies (like express) and skips devDependencies (like nodemon). It cuts down build times and keeps your container images smaller.