0

I am deploying a nodejs app I have tried two alternatives but I can't understand what's the better approach in terms of performance.

The first approach I tried is to lunch using pm2 npm start (which in my case call npx http-server ./ -p 8085 -o -c-1).

Then using Nginx I proxy_pass the port 8085 to myexample.org/app.

The second approach is to simply put the application in my root directory so that Nginx can directly serve myexample.org/app.

I can't understand the advantages and the disadvantages of the two approaches in both the apps seem working fine. Can you give me some reason I should opt for one approach instead of the other? Is there a better approach?

2
  • It is not clear what exactly is your second approach, as nginx can serve directly only static files.
    – AlexD
    Feb 6, 2021 at 9:53
  • @AlexD Thanks for you comment, I am deploying this app github.com/ProjectMirador/mirador if I put the content of Mirador integration test in a dir served by nginx I am able to use the app. I think nginx is serving directly the Javascript to the client
    – G M
    Feb 6, 2021 at 10:08

1 Answer 1

1

You are mixing serving Javascript files to the browser and serving node.js app as a backend application.

It seems that your node.js app (npx http-server) is an HTTP server itself and it serves your static files to the browser. You don't need to run npx http-server behind nginx if you only need to serve static files to a client browser.

But if you need to run a real node.js app then you can't just drop it into nginx root folder as nginx can serve directly only static files and you need to use something like proxy_pass with backend apps.

1
  • +1 thanks for the answer, I was quite confused because it seems that node was a requirement. But in this case how can I achieve load balancing for the "static applications" with pm2 I could start several server and create an upstream with nginx, with static applications what can I do?
    – G M
    Feb 7, 2021 at 8:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .