Basic server questions

Hello, :wave:

I basically only understand the components of front end development and even in that, I still have a lot to learn. As I study, I come across mentions of servers. Theres lots of talk about building your own server, communicating with your own server, making server requests and using secure code to protect from attacks etc. And of course In VS code I use ā€˜open with live serverā€™ , but I really have no idea what that means :rofl:.

My question is, what exactly is a server used for? From my limited perspective, I only understand front end development. Like browser and DOM stuff. So , why would a basic website that I might create need a server? What would be the benefits of having or building my own server? For example If I was to create a basic portfolio website, would I benefit from having a server in that scenario? Are there ways that customizing and working with a server could benefit my front end development?

Im really curious about this because I know its a pretty important and large part of web development that I have no clue about, and would like to have a better understanding of how things work.

What are some ways that servers can be built and customized to serve individual needs? :thinking:

In a typical scenario, thereā€™s a communication happening between a client and a server.

Normally clients perform requests, and the server is responsible for handling those request properly.
For example when you hit google.com you as a client are making a GET request to googleā€™s server to please have the ā€œhomepageā€.

Thatā€™s what the VSCode extension is doing, is spinning up a small server locally to serve your local requests.

Eventually you will want to move out of your local environment and make things accessible to the world, and thatā€™s when you publish your work to a place where itā€™s publicly accessible either on your own infrastructure or using a service.

And your need of a server may just stop there, simply serving something meant for the public.
But often times your needs will grow beyond that.
Think of user log-in/authentication.
Or registering a user email for a newsletter.
Or adding a new post to the comment section.

All those actions performed by clients, needs to me somewhat handled, and thatā€™s the server job.

Hope this explain things a bit.


Not to overcomplicate things, but nowadays thereā€™s also a popular paradigm called ā€œserverlessā€.
Meaning that you try to work without a server as much as possible, and rely on modern cloud services to run your custom code on certain events, reducing the need of an actual server for simpler cases.

1 Like

So you have a computer with, say, a database on it. No-one else can access that database unless theyā€™re sitting at your computer. If you want someone else to be able to access it in other computers, say, via an internet connection, you need to make it available on that network. So you install a program called a web server (I mean you could write your own, but thatā€™s a wee bit out of scope) which translates incoming messages of a specific format from the network into stuff you can use and letā€™s you send messages back out. Then you can make it so that when certain messages arrive, you get something from the database and send it back.

NodeJS, for example, has a server built into the program. With a Node application, you upload itā€™s constituent files somewhere, on a computer in some data centre, and you tell it to start, then it just sits on that computer and runs, waiting for incoming connections. Or a website, what you generally do is upload the files somewhere that already has a web server installed. And when you put those files in a specific directory, the web server knows to serve them when requests come in.

You have to do that because generally there has to be one place where your program runs. If you make an online shop, for example, users canā€™t just download the whole ā€œshopā€ program and use it on their own computers without a network: itā€™s not connected to anything. It would be like having a copy of a physical shop in your living room, except that everything in it is just photographs of the goods & the money is just pretend notes.

Or if you make a website, it has to be hosted at a specific place. If you have some control system for some machinery, it canā€™t just live on a userā€™s computer, thereā€™s a physical thing it needs to be connected to.

You canā€™t do anything particularly useful, internet-wise, without servers. Single-player games, or single-user applications like calculators or drawing programs, theyā€™re fine, you donā€™t need a server (edit: except how would you download them? You couldnā€™t. You would have to actually go and get the programs on physical media, as happened pre-internet). But most anything internet-related has to actually live somewhere, a physical location that can be accessed via a URL, and that place canā€™t be a single persons computer.

ā€œServerlessā€ is little bit of a misnomer, it means ā€œon a serverā€. Itā€™s just that you donā€™t have to set up and manage that server yourself.

1 Like

So gathering from what you both have said, a server is the physical location of stored data that serves the code to a website.Like where the code of the website lives. And if people make certain requests on that website, that processing of said request happens in the server and the server sends back information based on user credentials and request type etc.

So building a server or working on a server basically means setting up the type of information that is accepted and sent back to the user during requests? For example adding the code to make a post on a blog site?

I thought a lot of that stuff happened in the browser? Cant alot of requests be done just through JavaScript without the need of a server? I mean, I guess I understand the need for a server if youā€™re dealing with multiple users. Like if you have something like Facebook or Twitter, you would need server(s) to store all of the unique information for individual users. But just theoretically, canā€™t that be done with just front end code like Javascript? :thinking:

Note that there is a physical server AND a software server. They work together to ā€œserveā€ your site to multiple users.

It is like a store in the basement. The basement itself does not serve anything if no guy picks up things from the basement.

A lot of things happen in the browser as well. All the Javascript is fired in the browser. But you can put together a page (ā€œrenderā€) on the server ready for the browser.

You need both a physical server and a software server. Your own computer can act as a physical server and the software server can also be installed on your own computer. But this is not a ā€œwebā€ site. It is an island where only you live.

Javascript is not needed for a web site. You do not need CSS either. But Javascript brings the ā€œbuttonsā€ to live. Sort of.

2 Likes

Where do those HTTP requests go though? They have to be requests to somewhere. You can use JavaScript, or you can just write <a href="some-link-to-something">, or submit a form to somewhere or whatever. But there has to be something at the other end.

Edit: The browser doesnā€™t just magically get {stuff} from the ether. It uses the networking facilities of the operating system to send out a request, then it sees what comes back.

A URL, thatā€™s an identifier for some resource somewhere. A URL has a domain, so like https://www.example.com/index.html, the domain name is example.com. in turn, for internet requests, the domain will refer to an IP address. An IP address is the numeric code that identifies a specific computer on the internet, same as a house address. It lets other systems on the network find that computer. So you buy a domain name, then you tell it what IP address you want to attach it to, then you can install a server on the computer with that IP address and run it. And when someone types the URL into their browser, it will go find your computer and do whatever {some program that relies on the server} does when it receives requests of that particular form.

1 Like

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