文章詳情頁
node.js - nojs的response.write()如何返回一個html
瀏覽:150日期:2023-10-02 18:57:04
問題描述
本人學生,正在鉆研js。由于聽人說前段開發也需要習慣在本地環境中開發web頁面就選擇了node作為本地環境。已搭建一個簡單node服務。
這是代碼
var http = require('http');//var path = require('path');http.createServer(function(requrest,response){response.writeHead(200,{'Content-Type': 'text/plain'});//var index = path.extname(’./index.html’);var index = ’<!DOCTYPE html>’+’<html>’+’<head>’+’<meta charset='utf-8'>’+’<title>你好nodejs</title>’+’</head>’+’<body>’+’node.js’+’</body>’+’</html>’;response.write(index);response.end();}).listen(8888);
在我從瀏覽器訪問時直接返回了字符串如圖
我還寫了一個html文件但是不知道如何讓node返回這個index.html給瀏覽器希望有朋有可以指點以下
問題解答
回答1: 標簽:
HTML
上一條:node.js - 使用npm安裝vue-cli后,vue還是不可用是什么原因?下一條:html5 - express4 + socket.io 如何在connection的回調外邊使用socket.emit方法
相關文章:
排行榜
