How to render normal html file in express.js

ExpressJs is a very popular framework for node.js, Express default provide stylus and jade tempting engine but if you don’t have much knowledge about stylus and jade then don’t worry you can use your old method normal html and css.

You can render easily your normal html page in express by res.sendFile() function in express routing.


var express = require("express");
var app     = express();
var path    = require("path");
  //__dirname : It will add the path of your project folder
console.log("Application running on port 5000");

Where index.html is your main landing page if you hit the url http://localhost:5000 then it’ll be your main landing page.

And if you have more pages then you can use same method to render your all html pages.
copy below code and paste it in your main app.js file

// rendering about us page
// rendering contact us page.

If you like this post please don’t forget to subscribe My Public Notebook for more useful stuff.