How to Create a Simple Web Server Using Express.js (Step-by-Step Guide for Beginners)


In the world of web development, having a basic understanding of how web servers work is essential. Whether you're building a portfolio site, an e-commerce app. you’ll need a server to handle incoming requests and send responses.
And that’s where Express.js comes in.
This article will guide you step-by-step on how to create a simple web server using Express.js, explain the concepts behind it, and help you understand how everything fits together.
Let’s dive in!
What Is a Web Server?
A web server is a program that listens to incoming client requests, processes them, and sends back a response (like HTML, JSON, or a file).
For example, when you visit https://www.google.com
, your browser sends a request to Google’s server, and the server responds with the homepage content.
We can build this kind of server using Node.js and Express.js.
What Is Express.js?
Express.js is a minimal and flexible web framework built on top of Node.js. It provides a powerful set of features to create web and mobile applications.
Express simplifies the process of building servers so we can focus more on building features instead of dealing with low-level HTTP logic.
Step-by-Step: Build a Simple Express Server
Step 1: Set Up Your Project Folder
Open your terminal and create a new folder for your project.
mkdir express-server
cd express-server
This is where all your code will live.
Step 2: Initialize the Project with npm
To manage packages and scripts, run the following:
npm init -y
This creates a package.json
file, which stores your project’s configuration and dependencies.
Step 3: Install Express.js
Now install Express.js:
npm install express
It will be added as a dependency in your package.json
.
Step 4: Create the Server File
Let’s create a file to write our server code.
touch index.js
Now open index.js
in your code editor.
Paste the following code:
const express = require('express'); // This imports the Express module.
const app = express(); // Create an express application
// Define a basic route
app.get('/', (req, res) => {
res.send('Hello, World! This is your first Express server!');
});
const PORT = 3000; // Set the port for the server
// Start the server
app.listen(PORT, () => {
console.log(`🚀 Server is running on http://localhost:${PORT}`);
});
Step 5: Run the Server
Go back to your terminal and run the file using Node.js:
node index.js
You should see:
🚀 Server is running on http://localhost:3000
Now open your browser and go to http://localhost:3000
— you’ll see:
Hello, World! This is your first Express server!
🎉 Congrats! You’ve just built a working web server!
Ready to Level Up?
You can now try:
Adding query parameters (
req.query
)Handling POST requests (
app.post
)Connecting with MongoDB (using Mongoose)
Deploying with Railway or Vercel
Express.js makes building web servers fast and easy — it's the perfect starting point for anyone stepping into backend or full-stack development. 🚀
Subscribe to my newsletter
Read articles from Renil Garala directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Renil Garala
Renil Garala
A web developer, certified in Java. Pursuing a BCA in the third year and currently learning full-stack web development from Chaicode.