How to Render HTML File in Node JS Express?
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.
npm install express
Create Server.js File
let's create server.js file with get and post route.
var express = require('express');
var app = express();
res.sendFile(__dirname + '/index.html');
app.listen(3000, () => console.log(`App listening on port 3000`))
Create index.html File
<p>This is simple html file call by ItSolutionStuff.com!</p>
This is simple html file call by ItSolutionStuff.com!
i hope it can help you...
We are Recommending you
- How to Get Query String Value in Node.js?
- Node JS Express Route with Parameters Example
- How to Create Route in Node JS Express JS?
- How to Generate 4,6,8,10 Digit Random number in Node JS?
- Node JS Read and Write Json File Example
- Node JS Find and Update Object in Array Example
- How to Get Data from Json File in Node JS?
- How to Remove Element from Array in Node JS?
- How to Push Element in Array in Node JS?
- How to use Underscore JS in Node JS App?