剛學(xué)node,遇到一個問題:假設(shè)項目目錄(D:test)下只有run.js和index.html文件,我希望用node運行run.js的時候,在瀏覽器訪問localhost:8888能夠訪問index.html文件的內(nèi)容,應(yīng)該怎么操作?
2 回答

慕容森
TA貢獻1853條經(jīng)驗 獲得超18個贊
如果非要用nodejs打開就這么寫
function detail(response, query_param){
fs.readFile('./sina_weibo.html','utf-8',function(err, data) {//讀取內(nèi)容
if(err) throw err;
response.setHeader('content-type', 'text/html;charset=utf-8');
response.writeHead(200, {"Content-Type": "text/plain"});
response.write(data);
response.end();
});
}
建議你用exress框架里面直接封裝好方法直接response.render('path');
- 2 回答
- 0 關(guān)注
- 6717 瀏覽
添加回答
舉報
0/150
提交
取消