Running multiple Node (Express) apps on same port

前端 未结 3 444
情话喂你
情话喂你 2020-11-29 16:27

I have multiple Node applications (build on Express framework).

Now I have placed them like this -

  • /var/www/app1
  • /var/www/a
3条回答
  •  醉话见心
    2020-11-29 17:20

    You can create one main app(say app) parallel to you apps, and have it initializing the secondary apps (in your case app1, app2, app3) using

    app.use('', require('./app1/yourApp.js')
    

    All your apps (app1, app2, app3) need to create app and export it by using

    var app = module.exports = express();
    

    You need not create instance of server or call app.listen in all the subapps; all the sub-apps can be served via main app listen port.

提交回复
热议问题