我已经使用node.js编写了一个简单的服务器。目前,服务器通过向浏览器写入“hello world”来响应。node.js代码在浏览器中使用localhost URL打开页面
的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);
我使用这个网址在浏览器中触发的“Hello World”的回应:
http://localhost:8080/
我希望能够打开一个基本的html页面,当我通过这样一个URL:
http://localhost:8080/test.html
我已经浏览了很多教程和一些堆栈溢出的帖子,但在这个特定的任务没有太多。有谁知道如何通过对server.js文件的简单修改来实现此目的?
这有帮助吗? [通过操作系统打开URL](https://www.npmjs.com/package/openurl) – mins
是的,这可能有帮助,我会研究它!谢谢 – nealous3