【发布时间】:2020-07-12 17:40:34
【问题描述】:
我已经写了这个 test.js
var http = require("http");
http.createServer(function (request, response) {
// Send the HTTP header
// HTTP Status: 200 : OK
// Content Type: text/plain
response.writeHead(200, {'Content-Type': 'text/plain'});
// Send the response body as "Hello World"
response.end('Hello World\n');
}).listen(8080,'192.168.1.5');
// Console will print the message
console.log('Server running at http://192.168.1.5:8080/');
我运行了命令 node test.js
C:\Users\ShalomAlexander\Documents>node test.js
Server running at http://192.168.1.5:8080/
可以从我的笔记本电脑和连接到同一 wifi 网络的设备访问此 URL。但是当我在智能手机上从 wifi 网络切换到移动网络时,我无法访问它。
那么我怎样才能让它在不同网络中的其他设备上工作呢?
【问题讨论】:
-
好吧,您只需将其托管在公共服务器上,而不是本地主机上。 (当我说“简单”时......)
标签: javascript node.js server request response