Install Express and Jade modules
NPM Install Express Jade--save
varExpress= Require (' Express ');varapp=Express();// set up a static resource directoryapp. Use(Express.Static(__dirname));// Set the template engine (Use jade templates here) app.Set(' view engine ',' Jade ')// Set Template Catalogapp.Set(' views ','./views ')//Port Monitoringapp.Listen( -)// Routingapp. Get('/jade ',function(Req,res) {// can useres.locals.xxPass Value Res.Locals.Persons= [
{name:'John', Age: -,Sex:'male'},
{name:'Dick', Age: -,Sex:'female'},
{name:'Harry', Age: -,Sex:'female'}]// You can also useRes.render ("[, data])to pass the value Res.Render(' Exp1 ',{Info:'This is a background pass.'}); })
New Views/exp1.jade:
DOCTYPEHTMLHTML HeadtitleExpressUseJade BodyDiv(style="Background-color: #FFCCDD;")ifUse<br> ifInfo spanInfoIt's got a value.<br> Div(style="Background-color: #CCFFDD;")Jadethe basic use h5#Get content:#{Info} h5!Get content:! {Info} h5Get content: =Info Div(style="Background-color: #DDFFCC;") eachUse - each per inPersons h5name:#{ per.name} Age:#{ per. Age} Gender:#{ per.Sex}
The results are as follows: