Running and managing nodejs applications on single server

前端 未结 5 601
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-31 21:19

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 try

5条回答
  •  北恋
    北恋 (楼主)
    2021-01-31 22:09

    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.

提交回复
热议问题