Featured Article

Build a Node JS Express Web Server Example Quickly

Adam Jul 13, 2026

Node.js, a JavaScript runtime built on Chrome's V8 engine, has revolutionized server-side programming by enabling developers to build highly scalable and efficient network applications. Express.js, a popular web application framework for Node.js, simplifies the process of creating web servers and APIs. Let's dive into an example of creating a simple web server using Node.js and Express.js.

Node.js Express Login example with MySQL database
Node.js Express Login example with MySQL database

Before we start, ensure you have Node.js and npm (Node Package Manager) installed on your system. You can verify the installation by running the following commands in your terminal:

an image of a computer screen with some text on it
an image of a computer screen with some text on it

Project Setup and Initialization

First, let's set up a new Node.js project and install the required dependencies.

HTTP method express
HTTP method express

1. Initialize a new Node.js project by running npm init -y. This will create a package.json file with default settings.

Installing Express.js

Top NodeJS Framework
Top NodeJS Framework

Next, install Express.js as a dependency by running npm install express. This command will download and install the latest version of Express into your project's node_modules folder.

Creating the Server

Now, let's create a new file named server.js and set up a basic Express.js server. Open your favorite code editor and write the following code:

Node.js Cheat Sheet for Web Development | Backend Basics & NPM Guide | AKTU Notes
Node.js Cheat Sheet for Web Development | Backend Basics & NPM Guide | AKTU Notes

```javascript const express = require('express'); const app = express(); const port = 3000; app.get('/', (req, res) => { res.send('Hello, World!'); }); app.listen(port, () => { console.log(`Server running at http://localhost:${port}`); }); ```

The code above requires the Express module, creates a new Express application, and sets up a simple route that responds with 'Hello, World!' when visiting the homepage ('/'). It also listens on port 3000 and logs a message to the console once the server starts.

Running the Server

To start the server, run node server.js in your terminal. Now, if you open your browser and navigate to http://localhost:3000, you should see the message 'Hello, World!' - a sign that your Express.js server is up and running.

Express.js Cheat Sheet for Web Development | Backend & Routing Notes | AKTU Notes
Express.js Cheat Sheet for Web Development | Backend & Routing Notes | AKTU Notes

Adding More Routes

Express.js makes it easy to add more routes to your application. Let's add a new route that responds with the current date and time when visiting '/date'.

Simplify Input Validation with Zod in Node.js
Simplify Input Validation with Zod in Node.js
Read CSV Files In NodeJS
Read CSV Files In NodeJS
Understanding routing of expressJS in Node.JS
Understanding routing of expressJS in Node.JS
Node.JS Cheatsheet
Node.JS Cheatsheet
Express js vs Node js
Express js vs Node js
Express.js Cheat Sheet for Beginners β€” Essential Syntax and Commands
Express.js Cheat Sheet for Beginners β€” Essential Syntax and Commands
Serving Website With Express: A Beginner's Tutorial
Serving Website With Express: A Beginner's Tutorial
web development  #website #webdev #html #javascript #css #node.js
web development #website #webdev #html #javascript #css #node.js
Best Node.js Project Ideas
Best Node.js Project Ideas
File Upload in Node js using Multer - Tutorialswebsite
File Upload in Node js using Multer - Tutorialswebsite
Top NodeJS Frameworks You Should Know
Top NodeJS Frameworks You Should Know
Introduction to NodeJS
Introduction to NodeJS
π—‘π—Όπ—±π—²π—·π˜€ console module provides a π—–π—Όπ—»π˜€π—Όπ—Ήπ—² class
π—‘π—Όπ—±π—²π—·π˜€ console module provides a π—–π—Όπ—»π˜€π—Όπ—Ήπ—² class
12 Best Node.Js Application Examples
12 Best Node.Js Application Examples
Node JS Vs React JS
Node JS Vs React JS
Creating Custom Middleware in Express.js β€” 3 Easy Steps Tutorial
Creating Custom Middleware in Express.js β€” 3 Easy Steps Tutorial
Node JS Key Features
Node JS Key Features
a man sitting in front of a computer screen with the words node on it
a man sitting in front of a computer screen with the words node on it
Ways To Read Files In NodeJS
Ways To Read Files In NodeJS

```javascript app.get('/date', (req, res) => { const currentDate = new Date(); res.send(`The current date and time is ${currentDate.toLocaleString()}`); }); ```

Now, when you visit http://localhost:3000/date, you'll see the current date and time.

Using Middleware Functions

Express.js allows you to use middleware functions to handle common tasks like request logging, parsing request bodies, and more. For example, let's add a middleware function to log incoming requests:

```javascript app.use((req, res, next) => { console.log(`${req.method} ${req.url} - ${new Date().toISOString()}`); next(); }); ```

Now, every time a request is made to your server, it will be logged to the console.

Conclusion and Next Steps

By following this example, you now have a basic understanding of creating a web server using Node.js and Express.js. You've set up a project, installed dependencies, created routes, and even added middleware functions. As you continue exploring Express.js, you can delve into topics like handling HTTP methods (POST, PUT, DELETE), working with JSON, and building more complex APIs. Don't forget to check out the official Express.js documentation for more examples and features. Happy coding!