Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 355
elreeda Avatar asked Jun 08 '15 14:06

elreeda


People also ask

How do I access localhost 3000 from another computer?

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.

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

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.

How many concurrent connections can Nodejs handle?

To address these issues, Node. JS uses a single thread with an event-loop. In this way, Node can handle 1000s of concurrent connections without any of the traditional detriments associated with threads. There is essentially no memory overhead per-connection, and there is no context switching.


2 Answers

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

like image 98
Bidhan Avatar answered Oct 11 '22 23:10

Bidhan


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.

like image 43
skrtbhtngr Avatar answered Oct 11 '22 22:10

skrtbhtngr