【发布时间】:2015-07-01 03:39:24
【问题描述】:
我使用 node.js 编写了一个简单的服务器。目前,服务器通过向浏览器写入“hello world”来响应。
server.js 文件如下所示:
var http = require("http");
http.createServer(function(request, response) {
response.writeHead(200, {"Content-Type": "text/plain"});
response.write("Hello World");
response.end();
}).listen(8080);
我在浏览器中使用这个 URL 来触发“hello world”响应:
http://localhost:8080/
当我传递这样的 URL 时,我希望能够打开一个基本的 html 页面:
http://localhost:8080/test.html
我浏览了许多教程和一些 stackoverflow 帖子,但关于这个特定任务的内容并不多。有谁知道如何通过对 server.js 文件的简单修改来实现这一点?
【问题讨论】:
-
是的,这可能会有所帮助,我会调查一下!谢谢
标签: html node.js url browser server