Search code examples
node.jswebserverpm2

Can we use PM2 to scale a node js webserver? What about port?


My question could be yet answered, but I couldn't find a precise answer to my specific question.

Imagine I have simple node.js app that start a webserver listining on port 3000

Is it at all possibile to instruct Pm2 to auto start new processes in case of excessive load?

If yes, what happen to listening port? I mean: if I start a second webserver on the same port, it cannot works. How could we handle this problemi in pm2 ?


Solution

  • may be this video can help you to find out your solution for this problem

    https://www.youtube.com/watch?v=6xIbVPyh9wo

    The cluster mode allows networked Node.js applications (http(s)/tcp/udp server) to be scaled across all CPUs available, without any code modifications. This greatly increases the performance and reliability of your applications, depending on the number of CPUs available.