-1

I am a beginner in node JS. and I am developing an express app, using firebase as a backend.

PROBLEM- the APP I am developing only listens to one specific port that I define (in this case: 3000).
So any code I write only takes effect on that specific port. How do I code an express app in such a way that it listens to (get) requests globally, for the entire website, rather that just one port.

THIS IS THE APP I'm DEVELOPING-

enter image description here

Artur
  • 19
  • 7
  • What do you mean by globally? – curious_coder Jul 05 '20 at 09:04
  • for instance, listen to ` .com/` or `http://localhost/` , rather than on a specific port like ` .com/3000` or `http://localhost/3000` – Artur Jul 05 '20 at 09:11
  • 1
    That's not how it works. Your app binds to a port on the host (conventionally exposed as the PORT environment variable), then the platform's router sends appropriate traffic to it. – jonrsharpe Jul 05 '20 at 09:13

1 Answers1

2

You probably need to get a bit more familiarized with the concepts involved here.

HTTP requests are, by all standard definitions, sent to ports 80 (http) or 443 (https). Your 'App' (website or API) doesn't 'have' any ports, an http app hears on ports 80/443 and answers to those calls.

That may sound conflicting with express's default 3000 port, but it really isn't. The idea is that you really, really want to put your app behind some sort of reverse proxy (e.g. nginx). Simplifying things a lot, that basically redirects all requests to the 80/443 ports on your reverse proxy to the 3000 port on the server running your code. If you don't want your app to be called with the port number (e.g. http://www.example.com:3000/ping), then you need to use the reverse proxy. Technically just setting the port number would also work, but that wouldn't take care of both http and https and a lot of other things reverse proxies do efficiently for you.

Check out this other question for a bit more context

Hope that helps to clear things a little bit for you!

(P.S. highly suggest copy-pasting any code as text instead of an image, images are a lot harder to work with for anyone answering your question, and will discourage folks from answering the question)