Reputation: 505
I inherited a Node.js code and got stuck with these lines
....
var app1 = express();
app1.listen(8080)
var app2 = express();
app2.listen(8081)
var app3 = express();
app3.listen(8082)
....
all these lines are in one js file called serverInit.js
each app1, app2 and app3 has its own routes and different code.
I am wondering how this really work? does Node create a separate thread for each app1, app2 and app3 or all the apps will be serviced by one thread ?
Thanks in advance
Upvotes: 0
Views: 144
Reputation: 144912
No, your application code (which includes the Express library) is single-threaded. Of course, Node itself is multithreaded, and the network I/O is handled on separate threads – but this is true whether you have one Express app or hundreds.
What you've done is create three instances of Express, and bound each to a different port. Requests on each port are dispatched to the matching Express instance.
Upvotes: 2
Reputation: 22905
There is one v8 instance (since it is possible for the three servers to share variables etc, it would be extremely difficult to arrange for multiple v8 instances). The application listens for network connections on all three ports, and app1 responds to requests on port 8080, app2 on 8081, and app3 on 8082.
Upvotes: 0