简体   繁体   English

如何在节点js中运行多个应用程序?

[英]How can i run more than one app in node js?

I have to run three separate app in node js listening port 80.Now i am using this method 我必须在节点js监听端口80中运行三个单独的应用程序。现在我正在使用此方法

app.get('/barcelona/*', function(request, response) {

});
app.get('/real_madrid/*', function(request, response) {

});
app.get('/manchester/*', function(request, response) {

});

When i change something in "barcelona" or "real_madrid" or "manchester" ,I have to restart all my application.If any syntax error , the whole app will down. 当我在“barcelona”或“real_madrid”或“manchester”中更改某些内容时,我必须重新启动所有应用程序。如果出现任何语法错误,整个应用程序将关闭。 I want something like php.the error in apps will not affect each other.How can i do this? 我想要像php这样的东西。应用程序中的错误不会互相影响。我怎么能这样做?

A common way to do this is to put a proxy in front, such as nginx . 执行此操作的常用方法是在前面放置代理,例如nginx The proxy can route requests to specific Node.js-based applications transparently. 代理可以透明地将请求路由到特定的基于Node.js的应用程序。

I will answer this in two parts. 我将分两部分回答这个问题。

  1. Handling exceptions . 处理异常 In Node.js, if an exception occurs in the execution of your application, the whole application will be brought down. 在Node.js中,如果在执行应用程序时发生异常,整个应用程序将被关闭。 The main reason of the same is the single threaded nature of JavaScript. 同样的主要原因是JavaScript的单线程特性。 Its always better to handle the exceptions in the application rather than leaving to the runtime. 它总是更好地处理应用程序中的异常而不是留给运行时。

  2. Re-deployment after changes / bug-fixes . 更改/错误修复后重新部署 I use Naught.js for managing my deployment in production. 我使用Naught.js来管理我在生产中的部署。 Naught.js will monitor your node process and it will restart the process if your application goes down. Naught.js将监视您的节点进程,如果您的应用程序出现故障,它将重新启动该进程。 After code changes, you can use Naught.js to deploy the changes. 代码更改后,您可以使用Naught.js来部署更改。 Naught.js will shutdown the old process only after bringing up a new process with the latest changes. 只有在使用最新更改启动新进程后,Naught.js才会关闭旧进程。 This will ensure zero downtime of your application. 这将确保您的应用程序零停机。 Forver also does something similar. Forver也做了类似的事情。

If you are looking for running multiple instances of your application, you can try this out. 如果你正在寻找运行应用程序的多个实例,你可以试试这个了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM