Design First Application Using Express (original) (raw)

Last Updated : 5 Aug, 2025

In NodeJS, the task of designing a server was very difficult, but after the introduction of ExpressJS, which is a lightweight web application framework for NodeJS used to build the back-end of web applications relatively fast and easily.

**Prerequisites

To get started with an ExpressJS application, NodeJS and NPM must be installed in your system.

Follow the article to inslall Node and NPM in your system - How to Install NodeJS

Steps to design an ExpressJS application

Step 1: Create a project directory

First, you need to create a project folder in which you want to keep your project

mkdir my-express-app
cd my-express-app

Step 2: Initialize the Node project

After that, you need to initialize the project to install different dependencies and to fully use NodeJS

npm init -y

Step 3: Install ExpressJS

Now it's time to install and add ExpressJS to your project using the following command.

npm install express

**Dependencies

"dependencies": {
"express": "^4.21.2"
}

Step 4: Create the server File

Create a file named server.js in your project directory and set up your basic Express server inside server.js

JavaScript ``

const express = require('express'); const app = express();

const PORT = 3000;

app.get('/', (req, res) => { res.send('Hello, Express!'); });

app.listen(PORT, () => { console.log(Server is running on http://localhost:${PORT}); });

``

Step 5: Run the Application

Start your server by running the following command in your current project directory that you are working upon

node app.js

Step 6: Visit the localhost

Visit http://localhost:3000 in your browser. You should see the message "Hello, Express!".

Screenshot-2025-03-05-105545

Visit the localhost

**Hooray! your first express application created successfully

Step 7: Add More Routes

Now, let’s add more routes to handle different types of HTTP requests, like GET and POST.

JavaScript `

app.get('/about', (req, res) => { res.send('About Page'); });

app.post('/submit', (req, res) => { res.send('Form Submitted'); });

`

Screenshot-2025-03-05-105721

/about route

Screenshot-2025-03-05-111145

post request at /submit rote

How the ExpressJS application works?

An ExpressJS application works by handling incoming HTTP requests, processing them, and sending back responses.

Why to use ExpressJS above other technologies?

Use cases of ExpressJS application

Conclusion

ExpressJS simplifies back-end development by providing a fast and flexible framework for handling HTTP requests. It’s perfect for creating RESTful APIs, serving static files, handling user authentication, and much more. By using Express, you can quickly develop web applications with a clear and easy-to-understand structure, while maintaining high performance and scalability.