Node.JS无法在互联网上工作

BRa*_*sad 10 porting forward-compatibility node.js

我在windows上有nodejs的基本webserver hello world app,它可以在localhost上运行.但是,当我从互联网上测试时,它无法连接.我在netgear路由器中设置端口转发.我错过了一步让我的nodejs服务器对外界可见吗?

谢谢.

var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World\n');
}).listen(1337, "127.0.0.1");
console.log('Server running at http://127.0.0.1:1337/');
Run Code Online (Sandbox Code Playgroud)

Bry*_*her 17

一定要听,0.0.0.0而不是127.0.0.1

127.0.0.1是一个仅对您的计算机可见的专用网络. 0.0.0.0监听所有接口,包括私有接口和公共接口(与NAT后面的公共接口一样).