17 Program to demonstrate Template Engine using Embedded-JS and ExpressJS

Program:

app.js:

var express = require('express');

var app = express();



app.set('view engine', 'ejs');



app.get('/home', function (request, response) {

    response.send("This is my HomePage");

});





app.get('/posts/:id', function (request, response) {

    response.render('blog',{'blog_post':request.params.id});

});



app.listen(5000);


/views/blog.ejs:

<!DOCTYPE html>

<html>

    <body>

        <h1> This is a Heading. </h1>

        <h1>

            <%= blog_post %>

        </h1>

    </body>

</html>


Output:

Template Engine using Embedded-JS and ExpressJS

Previous
Next Post »