Approach 1 Using Basic Routes
It is simple to print Hello World by defining a root URL (“/”). When a GET request is made to the root URL, the server responds with “Hello, World!”.
Example: Below is the example to print hello world using basic routes implementations.
Javascript
const express = require( 'express' ); const app = express(); app.get( '/' , (req, res) => { res.send( '<h1> Hello, World! </h1>' ); }); app.listen(8000, () => { console.log(`Server is listening at http: //localhost:8000`); }); |
Output:
Print hello world using Express JS
In this article, we will learn how to print Hello World using Express jS. Express JS is a popular web framework for Node.js. It provides various features that make it easy to create and maintain web applications.