Hello World in Express Js

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.
npm install expressThe above command will install the Express Js into the application folder(express-01).
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.



