基于node的局域网服务器,怎样才能让在同一局域网下的其他电脑访问

var http = require('http');

http.createServer(function (request, response) {

response.writeHead(200, {'Content-Type': 'text/plain'});

// 发送响应数据 "Hello World"
response.end('Hello World\n');

}).listen(80);

阅读 10k
4 个回答
var http = require('http');
http.createServer(function (request, response) {
    response.writeHead(200, {'Content-Type': 'text/plain'});
    // 发送响应数据 "Hello World"
    response.end('Hello World\n');
}).listen(80, '0.0.0.0');

listen方法有很多可选参数的,文档地址

端口绑定在0.0.0.0或者ip

别人输入你的电脑的当前ip地址就可以吧!
在命令行中输入ipconfig可以查看自己的ip

clipboard.png

把localhost改成自己的ip地址就能访问了

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
宣传栏