Node.js - do I need to reinstall all the modules on the production server when deploying the Node.js app

白昼怎懂夜的黑 提交于 2019-12-06 05:12:36

I always try to use the latest versions of the required modules. Node.js is still very young and whenever a module is updated it often brings bugfixes, speed improvements, etc. I install modules locally, test my code on them and finally use them in production. When you install them with npm install module --save they are automatically added to your package.json file as dependencies.

Using git for version control and deployment I usually put the node_modules folder into my .gitignore file. It is therefore not uploaded to my server. On the server you just have to run npm install to install all your required modules, which is much faster than installing them one by one.

This workflow is also used by heroku.

You should definitely copy node_modules if possible.

If you re-download them at the server, you run a risk of getting slightly different versions of the modules in use. Even if you require a strict module version X, that module can again have wildcard dependencies to other modules Y Z. This means that if Y is updated and you publish to the server, it will now run using different code for Y than what you used for your local testing and validation.

In some cases you may not even have a required module available at deployment time, because the author has decided to de-publish the package for whatever reason.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!