ItSolutionStuff.com

How to Render HTML File in Node JS Express?

By Hardik Savani • June 16, 2021
Node JS

In this article we will cover on how to implement how to render html file in node js express. i explained simply step by step node js route to html page. you can understand a concept of node js redirect to html page. you will learn node js express render html.

In this example, i will give you very simple example of how to render html file in node js express project. we will use sendFile() to render html file, let's see bellow example.

Create Node Project:

you can run bellow command to create node app.

mkdir my-request-app

cd my-request-app

npm init

Install Express:

npm install express

Create Server.js File

let's create server.js file with get and post route.

server.js

var express = require('express');

var app = express();

app.get('/',function(req,res) {

res.sendFile(__dirname + '/index.html');

});

app.listen(3000, () => console.log(`App listening on port 3000`))

Create index.html File

index.html

<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

<title></title>

</head>

<body>

<p>This is simple html file call by ItSolutionStuff.com!</p>

</body>

</html>

Output:

localhost:3000/

This is simple html file call by ItSolutionStuff.com!

i hope it can help you...

Tags: Node JS
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

How to Get Query String Value in Node.js?

Read Now →

Node JS Express Route with Parameters Example

Read Now →

How to Create Route in Node JS Express JS?

Read Now →

How to Generate 4,6,8,10 Digit Random number in Node JS?

Read Now →

Node JS Read and Write Json File Example

Read Now →

Node JS Find and Update Object in Array Example

Read Now →

How to Get Data from Json File in Node JS?

Read Now →

How to Remove Element from Array in Node JS?

Read Now →

How to Push Element in Array in Node JS?

Read Now →

How to use Underscore JS in Node JS App?

Read Now →