14

I am new to Node.js. I have built my first Node.js server. I am doing some research to improve performance of node js server in production. So I learned about NGINX and Process Manager(PM2).

NGINX:

  1. It can load balance the incoming requests.
  2. It can act as reverse proxy for our application.

PM2:

  1. It can divide our application as clusters though it has in built load balancer.
  2. We can monitor and restart application when crashed.

Can we use both for production?

Though load balancer is there in PM2 can I use only PM2?

What is the advantage of using NGINX over PM2?

If I use Load balancer using NGINX and clustering using PM2, will it give better performance than using only one (NGINX or PM2)?

Ravi Teja Kumar Isetty
  • 1,559
  • 4
  • 21
  • 39

1 Answers1

28

This is a huge topic but let me help and give you some pointers.

Nginx is much more than just a reverse proxy. It can serve static content, can compress the response content, can run multiple apps on different port on the same VM and much more.

PM2 essentially helps you to scale throughput of your service by running it in cluster mode and utilizing all the cores of the box. Read this stackoverflow answer to understand more on this.

Now to answer your question

Can we use both for production?

Yes and you should. Nginx can run on port 80. PM2 can run on port 3000 (or whatever port) which can then manage traffic within the instances of the app.

gzip alone will make a huge difference in the app end user performance.

Here is a good article in case you need code help on how to set it up

Ryker
  • 446
  • 3
  • 14
AbhinavD
  • 6,892
  • 5
  • 30
  • 40
  • 1
    The last url points to pm2 homepage with no article, please update it – Peter Moses Jan 14 '19 at 12:42
  • if you run sudo on pm2 you can get it to boot to port 80. – johndpope Jun 11 '19 at 02:25
  • PM2 uses node cluster for the proxy which is WAY slower than Nginx proxy. So what you suggesting is actually a bad solution, instead Nginx should do the proxy and PM2 should do no proxying. – Mick May 13 '20 at 09:50