在NodeJS中使用art-template的方法案例

第一步:下载安装art-template
安装命令:

 npm install art-template

该命令在哪执行就会把包下载到哪里。默认会下载到 node_modules 目录中 node_modules 不能修改。
在NodeJS中使用art-template的方法案例
第二步使用:
模板引起最早就是诞生于服务器领域,后来才发展到了前端。
在需要使用的文件模块中加载 art-template

var tem = require('art-template');

加载进来了 就可以使用art-template的API方法了

案例:art-template和 fs的结合使用。
模板引擎不关心结构

var tem = require('art-template');
var fs = require('fs');
fs.readFile('./http.html', function (error, data) {
    if (error) {
        return console.log('文件读取失败!');
    }
    //fs读取的文件是属于二进制文件,需要把他转化字符串
    var res = tem.render(data.toString(), {
        name: 'asdfasdfas',
        age: 18,
        title: '谢小新'
    })
    console.log(res)
})

在NodeJS中使用art-template的方法案例