Node.js is an early adopter of frameworks shipping with an easy-to-use web server within the standard library. Previously, with languages like PHP or Python, one would need either a web server with specific support for the language or the ability to set up some sort of that works with the language. With Node.js, one can write an application that directly handles HTTP requests. As a result, the temptation is to write applications that handle requests for multiple domains, listen on multiple ports (i.e. HTTP and HTTPS), and then expose these applications directly to the Internet to handle requests.

  1. It adds unnecessary complexity to the application by diluting its focus.
  2. It prevents horizontal scalability.

See for a more thorough discussion of why one should opt to use a reverse proxy.

  1. The app needs TLS termination.
  2. The app needs to redirect HTTP requests to HTTPS.
  3. The app needs to serve multiple domains.
  4. The app needs to serve static resources, e.g. jpeg files.

There are many reverse proxy solutions available, and your environment may dictate the solution to use, e.g. AWS or GCP. Given the above, we could use HAProxy to solve these requirements:

  1. httpGet:
  2. port: 4000
  3. periodSeconds: 30
  4. timeoutSeconds: 3
  5. successThreshold: 1