How could others, on a local network, access my NodeJS app while it's running on my machine?

后端 未结 15 1626
旧时难觅i
旧时难觅i 2020-12-02 07:55

I have a pretty straight-forward question. I made a web game with NodeJS, and I can successfully play it by myself with multiple browser windows open side-by-side; however,

相关标签:
15条回答
  • 2020-12-02 08:14

    your node.js server is running on a port determined at the end of the script usually. Sometimes 3000. but can be anything. The correct way for others to access is as you say...

    http://your.network.ip.address:port/ e.g. http://192.168.0.3:3000

    check you have the correct port - and the ip address on the network - not internet ip.

    Otherwise, maybe the ports are being blocked by your router. Try using 8080 or 80 to get around this - otherwise re-configure your router.

    0 讨论(0)
  • 2020-12-02 08:16
    var http = require('http');
    http.createServer(function (req, res) {
    }).listen(80, '127.0.0.1');
    console.log('Server running at http://127.0.0.1:80/');
    
    0 讨论(0)
  • 2020-12-02 08:25

    If you are using a router then:

    1. Replace server.listen(yourport, 'localhost'); with server.listen(yourport, 'your ipv4 address');

      in my machine it is

       server.listen(3000, '192.168.0.3');
      
    2. Make sure your port is forwarded to your ipv4 address.

    3. On Windows Firewall, tick all on Node.js:Server-side JavaScript.

    0 讨论(0)
提交回复
热议问题