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

后端 未结 15 1627
旧时难觅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:06

    Faced similar issue with my Angular Node Server(v6.10.3) which set up in WIndows 10. http://localhost:4201 worked fine in localhost. But http://{ipaddress}:4201 not working in other machines in local network.

    For this I updated the ng serve like this

    //Older ng serve in windows command Prompt
    
    ng serve --host localhost --port 4201
    
    //Updated ng serve
    //ng serve --host {ipaddress} --port {portno}
    ng serve --host 192.168.1.104 --port 4201
    

    After doing this modification able to access my application in other machines in network bt calling this url

    http://192.168.1.104:4201  
    //http://{ipaddress}:4201
    
    0 讨论(0)
  • 2020-12-02 08:07

    And Don't Forget To Change in Index.html Following Code :

     <script src="http://192.168.1.4:8000/socket.io/socket.io.js"></script>
     <script src="http://code.jquery.com/jquery-1.6.2.min.js"></script>
    
     var socket = io.connect('http://192.168.1.4:8000');
    

    Good luck!

    0 讨论(0)
  • 2020-12-02 08:10

    Make sure the server is running, either by using 'npm start', or 'nodemon' in the command line window.

    0 讨论(0)
  • 2020-12-02 08:11

    I had the same question and solved the problem. In my case, the Windows Firewall (not the router) was blocking the V8 machine I/O on the hosting machine.

    1. Go to windows button
    2. Search "Firewall"
    3. Choose "Allow programs to communicate through Firewall"
    4. Click Change Setup
    5. Tick all of "Evented I/O for V8 Javascript" OR "Node.js: Server-side Javascript"

    My guess is that "Evented I/O for V8 Javascript" is the I/O process that node.js communicates to outside world and we need to free it before it can send packets outside of the local computer. After enabling this program to communicate over Windows firewall, I could use any port numbers to listen.

    0 讨论(0)
  • 2020-12-02 08:12

    The port is probably blocked by your local firewall or router. Hard to tell without details.

    But there is a simple solution for which you don't have to mess with firewall rules, run node as a privileded process to serve on port 80, etc...

    Check out Localtunnel. Its a great Ruby script/service, which allows you to make any local port available on the internet within seconds. It's certainly not useful for a production setup, but to try out a game with colleagues, it should work just fine!

    0 讨论(0)
  • 2020-12-02 08:13
    const express = require('express');
    
    var app = express();    
    app.listen(Port Number, "Your IP Address");
    // e.g.
    app.listen(3000, "192.183.190.3");
    

    You can get your IP Address by typing ipconfig in cmd if your Windows user else you can use ifconfig.

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