Use EJS as Template Engine in Node.js Use EJS as Template Engine in Node.js Use EJS as Template Engine in Node.js

 

Use EJS as Template Engine in Node.js Use EJS as Template Engine in Node.js Use EJS as Template Engine in Node.js Use EJS as Template Engine in Node.js 


/////////////////////////////// ////////////////////////////////////////////

command line
npm install ejs
etemp.js

// Set express as Node.js web application
// server framework.
// To install express before using it as
// an application server by using
// "npm install express" command.
const express = require('express');
const app = express();

// Set EJS as templating engine
app.set('view engine', 'ejs');
app.get('/', (req, res) => {
 
    // The render method takes the name of the html
    // page to be rendered as input.
    // This page should be in views folder  
    // in the root directory.
    let data = {
        name: 'Akashdeep',
        hobbies: ['playing football', 'playing chess', 'cycling']
    }
 
    res.render('home', { data: data });
});
 
const server = app.listen(8080, function () {
    //console.log('listening to port 4000')
});

///// view/home.ejs /////////////////


<!DOCTYPE html> <html> <head> <title>Home Page</title> <style type="text/css" media="screen"> body { background-color: skyblue; text-decoration-color: white; font-size: 5em; } </style> </head> <body> Hobbies of <%=data.name%> are:<br /> <ul> <% data.hobbies.forEach((item)=>{%> <li> <%=item%> </li> <%});%> </ul> </body> </html>

Comments

Popular posts from this blog

how manage leads mangement system user and manager auto assign in php how manage leads mangement system user and manager auto assign in php how manage leads mangement system user and manager auto assign in php

How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php How to add date filter in php

How to Run a Flask framework in Python How to Run a Flask framework in Python How to Run a Flask framework in Python How to Run a Flask framework in Python How to Run a Flask framework in Python How to Run a Flask framework in Python How to Run a Flask framework in Python