view engine used for template in express framework ,
differ type of view engine available in the express framework ,
1) ejs
how EJS work in node JS Express framework
install ejs
npm i ejs
use it with your express framework project
app.set('view engine','ejs');
make a folder named " views " in your project
declare "views" folder named as view folder
app.set('views',path.join (__dirname , 'view'));
make the view file named "index.ejs" in views folder
index.ejs
<html>
<head>
<link rel="stylesheet" href="bower_components/boostrap/dist/css/boostrap.css"/>
</head>
<body>
<div class="container">
<h1><%= title %></h1>
</div>
</body>
</html>
load view index.ejs by render method
app.get("/",function(req,res){
res.render('index')
});
2. jade
how jade work in node JS - Express framework
install jade
npm i jade
use it with your express framework project
app.set('view engine','jade');
make a folder named " views " in your project
declare "views" folder named as view folder
app.set('views',path.join (__dirname , 'view'));
make the view file named "index.jade" in views folder
index.ejs
doctype html(xmlns='http://www.w3.org/1999/xhtml', lang='en-GB', xml:lang='en-GB')
head
link(rel='icon', href='favicon.ico')
|
title
body
#background.container-fluid
load view index.ejs by render method
app.get("/",function(req,res){
res.render('index')
});