Home > OS >  What is the relation between the server of a web host and the server I create in Node.js?
What is the relation between the server of a web host and the server I create in Node.js?

Time:04-14

If I understand it correctly, when I decide to use the services of a web hosting company to make my website public, they provide me with space on a server (a physical machine) to store my files on. But what is the relation between this machine and the server that I create using Node.js: const server = http.createServer()? Is the code I write in Node just instructions telling the machine that my files will be stored on how to work? And does this machine also receive any instructions (in the form of computer code) from the hosting company (the owner of the server)? If so, do my instructions for the machine and those from the hosting company interact with each other in any way?

CodePudding user response:

The word "server" has two different meanings: First, it's a physical service, and second, it's a program. For it to work, you need both, the hardware and the software.

CodePudding user response:

This is not quite as simple a question as one might imagine. First, there are multiple different interpretations of the word "server".

  1. A "server" can refer to the actual hardware such as a physical piece of computing equipment that runs an operating system and provides OS services such as file storage, network connectivity and program execution. As in "I'm buying a server box from Dell to run my client/server program on". We can refer to this as the "server hardware".

  2. The term "server" is also often used to describe a server process running on some hardware that provides some service (usually, but not always via a networked connection). So this type of "server" would run on some server hardware (as described on point #1). We can refer to this as the "server process".

  3. At a finer granularity of detail, a "server" can also be a specific type of listening code within your server process that is listening for specific types of incoming connections. For example, your server process may contain a listening http server. A given server process can contain multiple listening servers. For example, you may have one listening server for http, another for https, another for administration, etc... We can refer to this as the "listening server".

  4. And, then in a hosting environment "server hardware" in point #1 can also be somewhat virtual where there's an actual physical server computer that hosts multiple virtual servers for tenants of the hosting company. Each tenant gets access to what feels like its own server, but actually there are multiple virtual servers running on one piece of server hardware that are all sharing the underlying server hardware resources (CPU, RAM, etc...), but are isolated from one another.

A typical hosting facility will have routing, firewall and proxy servers facing the internet that accept inbound connections and route them to the right port and server within the hosting facility (based on their own internal configuration). Except for the most expensive hosting plans which give you your own server hardware, your server process will be running on some sort of virtual server (sharing the actual server hardware with other tenants in a fairly transparent way).

So, your server process which you create when you run your nodejs application will be running on some virtual server. Within that server process, you can creating listening servers with let server = http.createServer(...) and server.listen(80) (or something equivalent).

The hosting company's infrastructure will route incoming requests destined for your domain to your listening servers.

they provide me with space on a server (a physical machine) to store my files on

Yes.

But what is the relation between this machine and the server that I create using Node.js: const server = http.createServer()?

Your server process runs on their "server hardware" (or virtual hardware). Your server process creates an http server (a listening server) that lives in your process and is listening for incoming http connections on a particular port.

Is the code I write in Node just instructions telling the machine that my files will be stored on how to work?

The code you write configures and initializes your listening http server and then the code you write processes incoming requests and decides what to do based on receiving them - what actions to take on the server and what response to send.

And does this machine also receive any instructions (in the form of computer code) from the hosting company (the owner of the server)?

Yes and no. The server hardware from the hosting company is carefully configured by the hosting provider and is running software they have provided and configured. It may or may not be running some custom software from the hosting company. For example, all the dynamic loading balancing that AWS provides in Amazon Web Services is highly customized software by Amazon. Other hosting plans or providers may just provide you with a fixed configuration that is more standard.

If so, do my instructions for the machine and those from the hosting company interact with each other in any way?

It's not entirely clear what you mean by this last point. You may have to code your server process and listening servers to follow some rules or APIs that the hosting provider requires. For example, in the simplest configuration where your code runs on a virtual server, you may have to start your http server on a specific port provided by the hosting provider. Their network hardware will route incoming requests on port 80 or 443 to your custom, assigned port in your own server process.

  • Related