0%

716_express框架_ejs初体验

//模板引擎是分离 用户界面和业务数据 的一种技术
//分离html和js

//导入EJS
const ejs = require("ejs");

const fs = require("fs");

let china = "中国";

let str = fs.readFileSync("01_html.html").toString();

let result = ejs.render(str, { china, china });

console.log(result);
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <h1><%=china%></h1>
  </body>
</html>