Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make node.js server accessible by public ip-address

Tags:

node.js

I've been trying to make an online multiplayer game using nodeJS and socket.io. I am able to access through localhost:3000 to test out my website, but then now I want my friends to access it too.

var express = require('express');
var app = express();
var server = require('http').Server(app);
var io = require('socket.io')(server, {});
server.listen(3000);

How can I make it so that other people can access my website using my public IP address that I found on http://cmyip.com, for example [external-ip]:3000.

I tried using ngrok, but it's very slow and socket.io that emits data every 30 ms is exceeding ngrok limit. Also, I don't want to use any DNS or other plugins, I just want it to be simple.

I'm using Mac OS so my firewall is disabled by default.

Here is my port-forwarding page: (my Local IP is 192.168.1.50) Am I doing it right? I have tried port-forwarding with games, and it works fine so I don't think it's my router. enter image description here

like image 458
Kongpon Charanwattanakit Avatar asked Oct 16 '25 02:10

Kongpon Charanwattanakit


1 Answers

If you sure that you don't have problem with router then you can try to listen 0.0.0.0 this mean you will listen external and internal IP adresses.

server.listen(3000,"0.0.0.0");

Also you still need to check your Brandmauer or Firewall.

like image 82
Leo Avatar answered Oct 18 '25 18:10

Leo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!