node 服务器 响应 html
var http = require("http"); var fs = require("fs"); var server = http.createServer(function (request, response) { response.writeHead(200, { "Content-type": "text/html" }) var stream = fs.createReadStream(__dirname + "/index.html", "utf-8"); stream.pipe(response); }); server.listen(4000, "127.0.0.1"); server.on("error", function (e) { if (e.code == "EADDRINUSE") { console.log("in error") setTimeout(function () { server.close(); server.listen(4000, "127.0.0.1") }, 1000); } }) console.log("server has started")
本文作者:进阶的哈姆雷特
本文链接:https://www.cnblogs.com/lbx6935/p/11905715.html
版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步