Node.js - 部署 Node.js 应用程序时是否需要重新安装生产服务器上的所有模块 [英] Node.js - do I need to reinstall all the modules on the production server when deploying the Node.js app
问题描述
我已经开发了我的第一个 Node.js pp.现在,它只是放在我的笔记本电脑上.
I have developed my first Node.js pp. For now, it just sits on my laptop.
在开发过程中,我不得不安装一些模块:
During development I had to install some modules:
npm install socket.io
npm install mysql@2.0.0-alpha3
npm install iniparser
npm install js-yaml
npm install nodemailer
我已经按项目"安装了所有这些,而不是全局安装.
I have installed all of them "per-project", not globally.
我的项目目录是这样的(我的代码都在push_server.js中):
The directory of my project looks like this (my code is all in push_server.js):
|
|--- push_server.js
|
|--- node_modules
|--- iniparser
|--- js-yaml
|--- mysql
|--- socket.io
|--- nodemailer
现在我想把这个项目推送到生产服务器.
Now I want to push this project to the production server.
我的问题是:我可以上传整个代码库(包括已安装的模块)还是应该只上传我的应用程序的代码并在服务器上一个一个地重新安装模块?
My question is: can I upload the whole codebase (including installed modules) or should I upload just the code of my app and re-install the modules one-by-one on the server?
注意:我的开发机器运行的是 Ubuntu 10.04,生产服务器运行的是 CentOS 5.3
Note: my dev machine runs Ubuntu 10.04, the production server runs CentOS 5.3
我认为所有这些模块都是由js文件组成的,所以应该没问题.
但是,npm 安装的模块是否有可能在本地机器上编译了一些代码,因此该代码可能无法在另一台机器上运行.另外,我怎么知道模块是否这样做?
I think all those modules are made up of js files only, therefore it should be allright.
However, is it possible that a module installed by npm compiles some code on the local machine, therefore that code is likely not to work on another machine. Also, how can I know whether a module does that?
希望这个问题不是太愚蠢 - 我刚刚开始使用 Node.js.
Hope the question is not too silly - I have just started with Node.js.
谢谢.
推荐答案
我总是尝试使用所需模块的最新版本.Node.js 还很年轻,每当一个模块更新时,它通常会带来错误修正、速度改进等.我在本地安装模块,在它们上测试我的代码,最后在生产中使用它们.当您使用 npm install module --save
安装它们时,它们会作为 dependencies
自动添加到您的 package.json
文件中.
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
.
使用 git
进行版本控制和部署 我通常将 node_modules
文件夹放入我的 .gitignore
文件中.因此它没有上传到我的服务器.在服务器上你只需要运行 npm install
来安装所有你需要的模块,这比一个一个安装要快得多.
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.
heroku 也使用此工作流程.
这篇关于Node.js - 部署 Node.js 应用程序时是否需要重新安装生产服务器上的所有模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!