从另一台计算机连接到 localhost:3000 | expressjs,nodejs
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30712141/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Connect to localhost:3000 from another computer | expressjs, nodejs
提问by elreeda
I'm currently working on a project and I would like to test it from another computer or phone. This computer is connected on the same network.
我目前正在做一个项目,我想在另一台电脑或手机上测试它。这台计算机连接在同一网络上。
How can I connect to http://localhost:3000?
我怎样才能连接到 http://localhost:3000?
I'm using expressjs(nodejsmodule ) as server.
我使用expressjs(nodejs模块)作为服务器。
回答by Bidhan
Configure your application to run on 0.0.0.0instead of 127.0.0.0(localhost). For example:
配置应用程序上运行0.0.0.0,而不是127.0.0.0(localhost)。例如:
app.listen(3000, '0.0.0.0', function() {
console.log('Listening to port: ' + 3000);
});
Then from another computer, connect to 192.168.1.11:3000(or whatever your local IP address is).
然后从另一台计算机连接到192.168.1.11:3000(或任何您的本地 IP 地址)。
回答by skrtbhtngr
Given that the port is bind to any IP address other than 127.0.0.1 (localhost), you can access it from any other system.
鉴于端口绑定到除 127.0.0.1 (localhost) 之外的任何 IP 地址,您可以从任何其他系统访问它。
To view your IP addresses, use ipconfig(Windows) or ifconfig(Linux) command.
Find out the IP which is in the same network as the "other system" from which you want access.
Then access it like, for example: 172.16.0.12:3000.
要查看您的 IP 地址,请使用ipconfig(Windows) 或ifconfig(Linux) 命令。找出与您要访问的“其他系统”位于同一网络中的 IP。然后,访问等,例如:172.16.0.12:3000。
PS: Remember to include the port 3000even when accessing it through another system. Also, hostnames may be used in place of IP addresses, if configured.
PS:3000即使通过另一个系统访问它,也要记住包括端口。此外,如果配置了主机名,则可以使用主机名代替 IP 地址。
回答by Yuri
your url should look like
你的网址应该看起来像
http://yourcomputername:3000
to get computer name open command prompt windows and type hostname then hit enter
获取计算机名称打开命令提示符窗口并输入主机名然后按回车

![node.js MongoNetworkError:第一次连接时无法连接到服务器 [localhost:27017] [MongoNetworkError: connect ECONNREFUSED 127.0.0.1:27017]](/res/img/loading.gif)