View engine setup

Other topics

Remarks:

install ejs using the following(I know it's obvious)

sudo npm install ejs --save

1:setting up the views

var express=require("express");    //express is included
var path=require("path");    //path is included 

var app=express();    //app is an Express type of application

app.set("views",path.resolve(__dirname,"views"));    //tells express about the location of the views in views folder
app.set("view engine","ejs");    //tells express that ejs template engine is used

2.EJS file example(refer 1.setting up... before this)

the following is an ejs file.

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>Hello, world!</title>
    </head>
    <body>
        <%= message %>
    </body>
</html>

3.rendering view with express(refer 2.EJS file... before this)

app.get("/",function(req,res){        
response.render("index",{                  //render the index when root(/) is requested
    message:"rendered view with ejs"
        });
});

4.after rendering final HTML is created(refer 3.rendering... before this)

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Hello, world!</title>
</head>
<body>
    message:"rendered view with ejs"
</body>
</html>

Contributors

Topic Id: 8104

Example Ids: 26121,26122,26123,26124

This site is not affiliated with any of the contributors.