Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running and managing nodejs applications on single server

Tags:

node.js

Is there a good way to run and manage multiple nodejs apps on a single server?

I've been looking at haibu and nodester, but they seem a little complex for what I am trying to do.

I also was looking at forever and I think that may work with the config file and web gui, but I am not sure how I am going to handle passing the port information via ENV or arguments.

like image 367
Ryan Schumacher Avatar asked Mar 05 '12 03:03

Ryan Schumacher


People also ask

Why should you separate express APP and server in NodeJS?

Applying a similar concept to the project structuring of Express, the separation of the application logic from the server allows the code to be modular and follow a MVC (Model-View-Controller) model. The separation is essential to reduce coupling and to encapsulate and abstract the inside logic of application.

Do you need a server to run node JS?

you likely need to serve them from different subdomains, or have Nginx as reverse proxy to serve them from single domain. Node is application server and is inefficient for serving static files and works best with Nginx or so. Any way, it's possible to do this with Node alone.

Can I run NodeJS on shared hosting?

Node. js is an open-source, cross-platform, back-end JavaScript runtime environment that runs on the V8 engine and executes JavaScript code outside a web browser. Node. js is not supported on Shared and Cloud hosting packages.


1 Answers

I use Supervisord & Monit, more details and configuration example here: Process Management at Bringr.

Moreover you can specify environnement variable directly from the supervisord configuration file (see sub-process environment). But I personally prefer to add these variables directly inside a ~/.bashrc on each machine.

If the port number isn't going to change for each application (but change between production & development environment). I'll recommend to specify them inside a config.json (or directly inside package.json). And the config.json will contain a different port number for each application depending on the environnement:

{
 myapp:{
  production:{port:8080},
  development:{port:3000}
 }
}

And inside myapp.js:

 var config = require('./config');
 app.listen(config.myapp[process.env.NODE_ENV].port)

With process.env.NODE_ENV declared in ~/.bashrc.

like image 57
FGRibreau Avatar answered Oct 16 '22 12:10

FGRibreau