«

ejs静态化

emer 发布于 2018-7-4 15:46   2437 次阅读     


var express = require('express');
var router = express.Router();
var fs=require("fs");
var ejs=require("ejs");
var path=require("path");
/* GET home page. */
router.get('/', function(req, res, next) {
 var data = fs.readFileSync(path.resolve(__dirname,"../views")+'/index.ejs','utf-8');
var content = ejs.render(data, { title: '我的' });
console.log(content);
  fs.writeFileSync('index.html', content);
  res.render('index', { title: 'Express' })
});

module.exports = router;