Approach 3 Using Middleware
Express middleware functions, distinct in their ability to interact with requests and responses, are employed in this case to handle all incoming requests and respond with a simple “Hello, World!” greeting.
Example: Below is the example to print hello world using middleware.
Javascript
const express = require( 'express' ); const app = express(); app.use((req, res) => { res.send( '<h1>Hello, World!</h1>' ); }); app.listen(8000, () => console.log( 'Server listening on port 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.
Contact Us