Program:
app.js:
/views/blog.ejs:
Output:
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: