The NPM install command typically behaves in a certain way.
When running npm install
on a production server, there are scenarios where it may not be possible (such as lack of compiling tools or restricted internet access). In addition, deploying the same project on multiple machines can waste CPU, memory, and bandwidth.
It is advisable to run npm install --production
on a machine that has the same libraries and node version as the production server. Then, compress the node_modules folder and deploy it on the production server. It is also important to keep the package-lock.json
file to specify versions accurately.
This approach allows you to build and test your code using development packages before trimming down the node_modules
directory for deployment.
Moving the node_modules folder is excessive and running npm install could potentially disrupt version dependencies. The recommended approach is to use npm ci
, which utilizes the package_lock
file to install required dependencies without altering versions. npm ci
is particularly useful for continuous integration projects. https://docs.npmjs.com/cli/ci.html
I hope this information proves helpful.