Skip to main content

Command Palette

Search for a command to run...

Hello World in Express Js

Updated
2 min read
Hello World in Express Js
A

Behold, the coding maestro! 🎩 Armed with PHP, Laravel, Linux, HTML, JavaScript, Jquery & Vue, I conquer both frontend and backend realms. 🚀 Pressure? No match for me. I deliver excellence and exceed expectations with flair. 🌟 Stay ahead, stay cool, and let's conquer the coding universe together! 💻

As per the rituals, the first thing to do to start with any language is print the Hello World, we can also say that as a programmer we love to say hello to the world in different languages.

Before proceeding, let's understand some basics about Express JS. So Express JS is a framework for Node.js. It provides easy ways to define routes, handle requests and responses with middleware, and integrate various features. With Express, you can create REST APIs effortlessly and efficiently manage tasks like user authentication and data handling. Its flexibility and large community support make it a go-to choice for developers building fast and robust web applications.

We need a few things installed in our machine to learn to Express js Node and the code editor of your choice, I recommend VS code as it is free, easy to use, and understandable.

Steps

Create a folder express-01 and a file with the name main.js you can name it whatever you want and run the below command.

  1. npm install express

    The above command will install the Express Js into the application folder(express-01).

  2. After installing Express open the main.js file in the code editor and write the below code.

     /**Importing the express Js */
     const express = require('express');
    
     /** Initializing the express application */
     const app = express();
    
     /** Register the route to accept the get request */
     app.get('/',(req,res,next) => {
         /** sending Hello World as a response*/
         res.send('Hello World');
     });
    
     /** Create server and start listing on the port of your choice */
     app.listen(3000);
    

    In the above code, we have imported the Express js to use the routing feature and also we have created an instance of an application to serve the get request and return the response.

In the next article, we will learn more about routing including the route verbs request and response and how to use them in the Express application.

Express Js

Part 3 of 3

In this series, we’ll explore Express JS from basics to advanced. Learn routing, middleware, ORM, and user authentication with Passport.js, REST API, and Stripe.js payment integration.

Start from the beginning

Express Js Middleware

Middleware is like checkpoints for the request to check, modify, and log for requests before it reaches the request handler function.

More from this blog

A

Abhishek Jha

15 posts

As a Full Stack Developer with four years of extensive expertise in the field of PHP, Laravel, MySQL, Linux, HTML, JavaScript, Jquery & Vue