我正在尝试找出如何加载和渲染基本的 HTML 文件,这样我就不必编写如下代码:
response.write('...<p>blahblahblah</p>...');
我刚刚发现one方式使用FS库。我不确定它是否是最干净的。
var http = require('http'),
fs = require('fs');
fs.readFile('./index.html', function (err, html) {
if (err) {
throw err;
}
http.createServer(function(request, response) {
response.writeHeader(200, {"Content-Type": "text/html"});
response.write(html);
response.end();
}).listen(8000);
});
基本概念只是原始文件读取和转储内容。不过,仍然对更清洁的选择持开放态度!
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)