I want to run multiple Node.js (Express) applications on the same server. I am aware of two different methods:
Using a reverse proxy to redirect requests to applications listening on different ports. For example
--> https://localhost:1001 --> https://localhost:1002
Using express middleware to run the applications on the same port (Running multiple Node (Express) apps on same port):
app
.use('/app1', require('./app1/index').app)
.use('/app2', require('./app2/index').app)
.listen(8080);
What are the advantages and disadvantages of these two methods?
I want to run multiple Node.js (Express) applications on the same server. I am aware of two different methods:
Using a reverse proxy to redirect requests to applications listening on different ports. For example
https://website./app1 --> https://localhost:1001 https://website./app2 --> https://localhost:1002
Using express middleware to run the applications on the same port (Running multiple Node (Express) apps on same port):
app
.use('/app1', require('./app1/index').app)
.use('/app2', require('./app2/index').app)
.listen(8080);
What are the advantages and disadvantages of these two methods?
Share Improve this question edited Aug 20, 2018 at 15:14 Luca Kiebel 10.1k7 gold badges32 silver badges46 bronze badges asked Aug 20, 2018 at 15:06 AliAli 1,1093 gold badges12 silver badges16 bronze badges 2- I think it's more a question for the software development munity, but I'll give it an answer – Prodigle Commented Aug 20, 2018 at 15:30
- i think you need something like this itnext.io/… – Ceddy Muhoza Commented Nov 29, 2019 at 3:04
1 Answer
Reset to default 5The biggest downside to running them both in express are that both your applications will be sharing Node resources. One server will be handling both requests, so all it's resources (Memory, CPU-especially as it's single threaded) will be shared. This also means that any security issues introduced to one app now affect both applications.
On the upside, you only have 1 set of overhead if your physical server is small, even though that single node process is sharing it's resources between 2 apps, your physical server is only having to run one Node process.
Optimally though, every app should have it's own Node process. It separates concerns, security, packages, resources. When it es to deployment it allows you to scale them separately, makes it easier to debug.
Basically unless you have a fairly good reason not to, you should separate them into 2 node apps.