How could others, on a local network, access my NodeJS app while it's running on my machine?
Solution 1
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 the 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.
Solution 2
If you are using a router then:
Replace
server.listen(yourport, 'localhost');
withserver.listen(yourport, 'your ipv4 address');
in my machine it is
server.listen(3000, '192.168.0.3');
Make sure
yourport
is forwarded to your ipv4 address.On Windows Firewall, tick all on Node.js:Server-side JavaScript.
Solution 3
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.
- Go to windows button
- Search "Firewall"
- Choose "Allow programs to communicate through Firewall"
- Click Change Setup
- 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.
Solution 4
One tip that nobody has mentioned yet is to remember to host the app on the LAN-accessible address 0.0.0.0
instead of the default localhost. Firewalls on Mac and Linux are less strict about this address compared to the default localhost address (127.0.0.1
).
For example,
gatsby develop --host 0.0.0.0
yarn start --host 0.0.0.0
npm start --host 0.0.0.0
You can then access the address to connect to by entering ifconfig
or ipconfig
in the terminal. Then try one of the IP addresses on the left that does not end in .255
or .0
Solution 5
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
Related videos on Youtube
theabraham
Updated on March 31, 2022Comments
-
theabraham about 2 years
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, I'd like to know if it's possible for other local machines to be able to access and play the game with me too.
I naively tried using this url:
my-ip-address:8000
and it won't work. -
theabraham about 13 yearsI switched to port to 8000, but I may have used my internet IP instead of the network's. I'll try this when I get home and report anything.
-
RobertPitt about 13 yearsYou should also go into your router and allow your ip,
192.168.0.3
to be able to forward port8000
, this way when your clients connect to your local ip, the router will allow them threw. -
Billy Moon about 13 years@Gisborne - did you try this - in fact, did you ever get home? We are all waiting here with baited breath!
-
Ricardo Tomasi about 13 years@RobertPitt port forwarding is usually just from the outside world to the local network. Computers in the same local network have no restrictions in default (and most common) router configurations.
-
Rishabh Agrawal about 8 yearsis it possible to replace my network ip by some string like instead of 192.168.0.3:8000 it would be mycoolapp.xyz ?
-
tnishada about 8 yearsI also had the same issue. this is working for the local area network ip but not working with internet ip. so i can not connect through internet. Why it can not be used internet ip ?
-
Dema over 7 yearsNgrok.com is now the way to go.
-
DaddyMoe over 7 years
ng serve --host 0.0.0.0
did the magic for me to allow connection on localhost -
DRAB over 7 yearsInterestingly, the application specified by "Evented I/O for V8 Javascript" is a standalone version of Node added by Adobe's Brackets editor. If you don't use Brackets, probably best not to allow this app. If you're running Node from a command line or another IDE (like Webstorm), the app you're looking for here is "Node.js: Server-Side JavaScript"
-
Lance about 6 yearsHow can you do that in a redhat server? My server only allow access to my node app when I turn off the firewalld service.
-
Anthony Cregan about 6 yearsSorry, I have no experience with that I'm afraid.
-
Pramesh Bajracharya almost 6 yearsI can't believe it was this simple. :) Thanks.
-
RyanOC over 5 yearsThis worked great. I can access my Parallels Windows VM from my Mac now, thanks!
-
danielsvane about 5 yearsI had 3 different listings for Node in my setup, one for domain/private/public, but one of them was missing the checkbox on the left side. This solved my problem.
-
EdGzi almost 4 yearsI get this error:
Error: listen EACCES: permission denied
-
Thomas Morris almost 4 years@LV98 Depending on how you are accessing it you will need to check firewalls or check you have permission to access the internet. Also you might need to go into the router to check its settings.
-
EdGzi almost 4 years@ThomasMorris I solved the issue now. My parameters were reversed and it didn't like it - that why it showed up with that error.
-
Thomas Morris almost 4 yearsMakes sense glad it was resolved. Be lovely if error codes could see this issue
-
AVAVT over 3 yearsJust want to add that in my case
Node.js: Server-Side JavaScript
was not listed in the app list initially. I had to chooseAllow another app...
and explicitly chose nodejs.exe -
Juliver Galleto over 2 yearsthis only works with nodejs installed in the machine, I have this electron app with nodejs running, upon installation nodejs not exist.
-
kaushalpranav over 2 yearsOnly this answer worked for me. Can you add a comment on how
localhost
is different in this case from the ipv4 address like192.168.0.3
. Thanks :) -
Alif over 2 years@kaushalpranav
localhost
points to the IP address127.0.0.1
which is is the IP address for any machine. A program in that same machine can access to the server hosted at127.0.0.1
. To expose the server to other computers in that router network, you have to use the IP assigned by the router; that is192.168.0.x
or something like this. In this stage, the server can only be accessed from any computers in the router network. However, that server is not yet available to the internet. -
Timo about 2 yearsBut this solution may not work in a Heroku app.
-
Timo about 2 yearsI think your answer can be improved. Where is the
io
package coming from? Is it a jquery package? How does it work, what can I do withsocket
? Maybe you can show a use case. -
manneym about 2 yearsThis did the trick.