Connect to localhost:3000 from another computer | expressjs, nodejs [duplicate]

╄→гoц情女王★ 提交于 2019-12-28 08:40:55

问题


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?

I'm using expressjs (nodejs module ) as server.


回答1:


Configure your application to run on 0.0.0.0 instead of 127.0.0.0(localhost). For example:

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).




回答2:


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.

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.

PS: Remember to include the port 3000 even when accessing it through another system. Also, hostnames may be used in place of IP addresses, if configured.




回答3:


your url should look like

http://yourcomputername:3000

to get computer name open command prompt windows and type hostname then hit enter



来源:https://stackoverflow.com/questions/30712141/connect-to-localhost3000-from-another-computer-expressjs-nodejs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!