您的位置:首頁技術文章
文章詳情頁

node.js - nojs的response.write()如何返回一個html

瀏覽:159日期: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);

在我從瀏覽器訪問時直接返回了字符串如圖

node.js - nojs的response.write()如何返回一個html

我還寫了一個html文件但是不知道如何讓node返回這個index.html給瀏覽器希望有朋有可以指點以下

node.js - nojs的response.write()如何返回一個html

問題解答

回答1:

node.js - nojs的response.write()如何返回一個html

標簽: HTML
相關文章:
国产综合久久一区二区三区