
Are you new to web development and eager to create your very first application using Express? Look no further! In this tutorial, we’ll walk you through the process of building a simple Express application that returns the classic “Hello World” response. By the end, you’ll have a solid foundation to start creating more complex and exciting web applications. So, let’s get started!
Setting Up Your Development Environment
To begin, make sure you have Node.js installed on your machine. You can download the latest version from the official Node.js website. Once installed, follow these steps:
1. Open your preferred command-line interface (CLI).
2. Create a new directory for your project.
3. Navigate to the newly created directory using the CLI.
4. Run the following command to initialize a new Node.js project:
npm init -y
5. Next, install Express as a dependency by running the following command:
npm install express
With the initial setup complete, we’re ready to start building our Express application.
Creating the ‘Hello World’ Application using Express
1. Open your favorite code editor and navigate to your project directory.
2. Create a new file called app.js (or any other name of your choice) and open it.
3. Import the Express module by adding the following line at the top of your app.js file:
const express = require('express');
4. Create a new Express application by adding the following line:
const app = express();
5. Define a route that responds with “Hello World” when accessed. Add the following code below the previous line:
app.get('/', (req, res) => {
res.send('Hello World');
});
app.get(‘/’, (req, res)) tells what to do when a get request at the given route (‘/’) is called. The callback function has 2 parameters, request(req) and response(res). The request object(req) represents the HTTP request and has properties for the request query string, parameters, body, HTTP headers, etc. Similarly, the response object represents the HTTP response that the Express app sends when it receives an HTTP request.
res.send() function takes an object as input and it sends this to the requesting client. Here, we are sending the string “Hello World!”.
6. Start the server by adding the following line at the end of your file:
app.listen(3000, () => {
console.log('Server running on port 3000');
});
app.listen() binds and listens for connections on the specified host and port. Port is the only required parameter here.
7. Save the changes.
Complete Code
const express = require('express');
const app = express();
app.get('/', (req, res) => {
res.send('Hello World');
});
app.listen(3000, () => {
console.log('Server running on port 3000');
});
Testing your Application
To test your application and see the “Hello World” response in action, follow these steps:
1. In your CLI, navigate to your project directory.
2. Run the following command to start the server:
node app.js
Once you run this command, you can observe following statement in the console:
Server running on port 3000
3. Open your web browser and visit http://localhost:3000 or http://127.0.0.1:3000.

Congratulations! You should see the “Hello World” message displayed on the page.
So, we’ve covered the basics of building your first Express application that returns a “Hello World” response. Express.js provides a simple yet powerful framework to develop web applications quickly and efficiently. By following the steps outlined above, you’ve gained a solid understanding of the process and are ready to explore further.
Remember, this is just the beginning. Express offers a wide range of features and functionalities to help you build more complex applications. So keep experimenting, learning, and building exciting projects with Express!
Keywords to search: creating first app using express, create first app using node express, node express app, expressjs tutorial, create a server using express
