nodejs 模板引擎ejs的简单使用

ejs1.js

/**
 * Created by ZXW on 2017/11/9.
 */
var ejs=require('ejs');




ejs.renderFile('./view/1.ejs',{name:'zhangshang','password':"123456"},function (err,data) {
  if(err) {
      console.log('失败')
  }else {
      console.log(data)
  }



});

1.ejs

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
登陆名:<%= name %>
登陆密码:<%= password %>
</body>
</html>

s输出效果:

原文地址:https://www.cnblogs.com/guangzhou11/p/7810114.html