Understanding Servers

Hello to everyone. I have a question about servers. What is a server? is it a computer? Or is it software running on a computer? For example, is node.js a server, if so why are we installing nginx? Why do we use both together? Thanks…

@ertugrulb7 Server is a device which you can make requests. It can be a computer or a Type-1 VM. It is not a software. Node.js is a javascript runtime for server side. It is not a server. And ngnix is a tool for server side scripting.

Hope This Helps

Thank you. Can you give me an example of how a node.js application and nginx work? I think I will understand this through an example. :slight_smile:

Can’t give an example for the specific programs, but doesn’t matter for the general concept:
A “server” got it’s name for “serving something” - it’s a computer with which users usually don’t interact with directly, but which programs send requests to either store data and/or save it. And users use those programs.

For example, the forum is sitting on a server. Meaning all it’s data is stored on a computer somewhere, that is running 24/7.
You interact with it via your browser, which sends pull-requests to get data (the html, CSS, JS…) and push-requests (hitting the submit-button on a post) to send data.

Node.js as a javascript runtime is basically a piece of JS-code (and maybe other stuff), that creates an environment in which you can write easier JS code (kinda like lego offers pre-made tiles which you can use to arrange in all kinds of manners, without the need to produce those tiles yourself).

On the server, you can think of it as two services. One is the database which stores all the text of the forum. The other is the database having the code that determines how the plain text is transformed into a visible website - you know, with code highlighting, with buttons for likes, edits, replies…
The code is also saved on the server and when you visit the forum, your browser requests that code from the server. And then that code requests the data from the database and the code get it’s answer, it builds the website.

1 Like

Thank you for the answer. What do nginx and node.js do? How they work on the server.

I once worked with vue.js and I will just assume it works similar to node.js
They are a toolkit, which don’t do anything on the server. When you visit the website, the server sends the JS code to you and your browser executes the JS code on your machine.

nginx according to wikipedia is a service that basically sits inbetween servers. Because a server is a computer, connected to the internet - it has bandwidth limits and memory and computational power just like your computer. So nginx offers some modules which can be used to modify how the servers are called. For example websites with a lot of traffic are hosted on several servers which all contain the same data. When many people visit the website, nginx will distribute them onto different servers so that they all can access the data without delay - whereas if all would visit the same server, the limited bandwidth would result in longer loading times.
The servers themself then need to have some programs which will exchange changes in data so that there are no differences.

nginx also offers other utilities. Ofcourse in itself, it’s again sitting on a server and takes the pull/push requests and distributes them to the other servers with the actual data. However the requests are only short texts, so it’s unlikely to run into a problem. The answers which for example contain a youtube-video would then not run through nginx, but go directly to the user.

Thank you for the answer. I hope I will understand them better when I start this journey… :slight_smile:

Hello @ertugrulb7.

A server is a piece of equipment in the telecommunication industry that has the responsibility of computing the incoming traffic.

The definition is generic on purpose because there are various ways of communicating through the internet and various protocols, so there’s no single catchphrase to get them all.

For example when you navigate with your browser to a page, you are making a GET request via HTTP/HTTPS. This means that there’s a machine somewhere that will listen to your request, process it, and respond to you.
In the case of a web page the response is some html/css/js (or similar).

This means that in theory “everything” can become a server, from Google super computers to a RasperryPI you buy on Amazon. As long as you configure them to accept incoming requests and instruct them to process and give some answers.

NodeJS is a JavaScript runtime that uses the V8 engine to “convert” your JavaScript code so that the computer will understand it.

Why it’s needed? When you first start with web development you can simply write JS and the browser “understand” it, but that’s not the case for your computer: you need to convert it into a format that your CPU will understand.

So NodeJS is not limited to just web servers, you can make any kind of programs (with limitations of course) like a small utility function that remove file from your computer, as long as you have installed the Node runtime that will “convert” your script into CPU language.

Nginx is a very (very) popular web server/software. It’s main strength are fault tolerance, which as you can imagine in the internet word, were you can have thousands of requests at the same time is a very important asset.
It’s mainly used as a load balancer, which as the name imply serve the purpose of choosing when/which request to take to avoid big spikes.
It’s also used a lot as a Proxy: an intermediate between the actual client request and the “final” server for the response.

So you can imagine a flow like this:

[client] - make HTTPS request

[nginx] - get the request first as a proxy.
Performs its tasks then decide to pass the request to your other server

[nodeJS] - you wrote a simple server.
Now you read the incoming request from the client;
decide it's valid so you reply

Hope this helps :sparkles:

Also don’t worry to get it all now, the internet is quite complex, and somehow magical at the same time :smiley:


Thank you for helping. Now I can understand better. Now I’m sure that the answer for the questions in my mind is here :slight_smile:

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.