test.ejs
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<% for(var i=;i<json.arr.length;i++){ %>
<div>用户名:<%=json.arr[i].user%> 密码:<%=json.arr[i].pass%></div>
<% } %>
</body>
</html>
ejs.js
ejs=require('ejs'); ejs.renderFile('./views/test.ejs', {json: {arr: [
{user: '李四', pass: ''},
{user: '张三', pass: ''},
{user: '丽华', pass: ''},
]}}, function (err, data){
console.log(data);
});
输出效果: