Web Development
What Is a Server? Types, Web Servers, and Node.js Setup
Demystify servers in this practical guide. Learn how servers work, explore different types of web servers, and build your own custom server using Node.js.

Hover to zoomEvery time you open a browser, type a URL, and hit enter, a silent conversation happens in milliseconds. Your browser requests a page, and a distant machine delivers it. But what is a server exactly, and how does it manage to handle thousands of these requests simultaneously without breaking a sweat? If you are planning a career in backend engineering, understanding this backend engine is your absolute square one.
At Squarebrackets, we teach our students that a server is not some mystical black box. It is simply a computer running specialized software, waiting to serve other computers. Let us break down how they work, look at the common types you will encounter in production, and write some JavaScript code to build a functional web server from scratch.
What is a server and how does it work?
A server is a physical machine or virtual instance configured to listen for incoming network requests and deliver resources to clients. A client can be your web browser, a mobile app, or even another server. This relationship is called the client-server model.
Unlike your laptop, which is optimized for user interaction, display, and gaming, a server runs headless without a monitor and is optimized for processing power, memory throughput, and network bandwidth. It runs 24/7, uses redundant power supplies, and relies on operating systems like Ubuntu Server, Red Hat Enterprise Linux, or Windows Server.
Here is the basic request-response lifecycle when you access a website:
- You type a domain name into your browser client.
- Your browser queries a DNS server to translate that domain into an IP address.
- The browser sends an HTTP/HTTPS request over the internet to that IP address on port 80 or 443.
- The web server software listening on that port receives the request, processes it, and finds the requested file or database record.
- The server sends back an HTTP response containing the status code and the requested content.
The different types of servers in modern tech stack
Servers are classified by the specific roles they play in an infrastructure. In a production environment, you rarely have a single machine doing everything. Instead, different specialized servers work together in a pipeline.
When looking at how backend requests flow, placing a reverse proxy in front of your application servers protects your private instances and handles SSL termination efficiently.
| Web Server | Application Server | |
|---|---|---|
| Primary Purpose | Delivers static files (HTML, CSS, JS, Images) | Executes business logic and dynamic code |
| Protocols Used | HTTP, HTTPS | HTTP, TCP/IP, gRPC, RMI |
| Examples | Nginx, Apache HTTP Server, IIS | Node.js, Apache Tomcat, WildFly, Gunicorn |
| Database Connection | Rarely connects directly to a database | Frequently queries databases and external APIs |
Beyond web and application servers, you will also work with Database Servers like PostgreSQL or MongoDB which store and retrieve data securely, Mail Servers for routing emails, and Proxy Servers that sit in front of application servers to balance traffic load.
How do web servers process requests?
Web servers use different concurrency models to handle multiple users at the same time. The two most common models are thread-based and event-driven.
Traditional servers like Apache use a thread-per-request model. When a user connects, the server spawns a new thread to handle that request. If you get 10,000 simultaneous users, you need 10,000 threads. This consumes massive amounts of RAM and CPU because of context switching.
Modern servers like Nginx and runtimes like Node.js use an event-loop model. They run on a single thread and use non-blocking, asynchronous I/O. When a request comes in for a database query, the server hands that task to the operating system and immediately moves to the next user request. When the database returns the data, an event is triggered, and the server sends the response. This is why a lightweight Node.js server can easily outperform a massive multi-threaded server on standard web workloads.
Step-by-step: Building a web server with Node.js
Let us build a real, working web server. We will use Node.js, a runtime environment that lets us run JavaScript outside the browser. Make sure you have Node.js installed on your system with version 18 or higher recommended.
First, create a new directory for your project, open your terminal, and initialize it with npm:
mkdir my-node-server
cd my-node-server
npm init -yNow, create a file named `server.js` and add the following code using Node's built-in HTTP module. We do not need any external libraries for this basic setup.
const http = require('http');
const PORT = 3000;
const HOSTNAME = '127.0.0.1';
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'application/json');
if (req.url === '/' && req.method === 'GET') {
res.end(JSON.stringify({ message: 'Welcome to the Squarebrackets Home API!' }));
} else if (req.url === '/status' && req.method === 'GET') {
res.end(JSON.stringify({ status: 'healthy', uptime: process.uptime() }));
} else {
res.statusCode = 404;
res.end(JSON.stringify({ error: 'Route not found' }));
}
});
server.listen(PORT, HOSTNAME, () => {
console.log(`Server running at http://${HOSTNAME}:${PORT}/`);
});To run your server, execute this command in your terminal:
node server.jsOpen your browser and navigate to `http://127.0.0.1:3000/`. You will see the JSON response. Try visiting `/status` or a random path like `/dashboard` to see how the routing logic responds to different inputs.
Scaling up: Why we use Express.js next
While the native `http` module is great for understanding the basics, writing complex routing, handling file uploads, and parsing cookies manually gets tedious. That is why production Node.js servers almost always use robust frameworks. To learn more about this workflow, read our guide on <a href="/blogs/creating-server-express-http-methods">Creating Server with Express and HTTP Methods</a>.
Express acts as a wrapper around the native HTTP module, giving you clean middleware support, simplified routing syntax, and built-in request parsing. Here is how clean the same server looks with Express:
const express = require('express');
const app = express();
const PORT = 3000;
app.use(express.json());
app.get('/', (req, res) => {
res.json({ message: 'Welcome to the Express Server!' });
});
app.get('/status', (req, res) => {
res.json({ status: 'healthy' });
});
app.listen(PORT, () => {
console.log(`Express server listening on port ${PORT}`);
});Where to go from here
Understanding what is a server is the foundation of building modern, scalable applications. From physical server racks to virtual cloud instances and lightweight Node.js runtimes, the core job remains the same: listening for requests and returning resources reliably. Ready to go deeper? Explore our specialized <a href="/mern-stack-microservices-gen-ai">MERN Stack with Microservices & Gen AI</a> program or master high-performance backend engineering with our <a href="/web-development-golang">Web Development with GoLang</a> course.
