jade-render-renderFile

var http = require('http');
var jade = require('jade');

http.createServer(function(req, res){
    res.writeHead(200,{
        //'Content-Type':'text/plain';//文本
        'Content-Type':'text/html'//展现html文件
    })

    //1、jade.compile
    // var  fn = jade.compile('div #{course}',{});
    // var html = fn({course:'jade'});
    // res.end(html);

    //2、jade.render
    // var html = jade.render('div #{course}',{course:'jade render'});
    // res.end(html);

    //3、jade.renderFile 文件路径,参数{pretty:格式化}
    var html = jade.renderFile('index.jade',{course:'jade render',pretty:true});
    res.end(html);
}).listen(1337,'127.0.0.1');

console.log('server running at 1337');

 

posted @ 2018-07-12 06:39  wzndkj  阅读(292)  评论(0编辑  收藏  举报