DEV Community

Cover image for How to access your localhost application on any device
Guga Cavalieri
Guga Cavalieri

Posted on

How to access your localhost application on any device

I have always had problems while trying to test my applications on my localhost machine. The process was so painful that I would have to do some crazy port forwarding on my router (yes, using my internet provider public IP) or even deploy to staging environment server and access it on the desired device (sadly I did it once 😢).

This was until the other day when my coworker (many thanks to Tays) came to me with a magical solution called ngrok. In a nutshell, ngrok exposes local servers behind NATs and firewalls to the public internet over secure tunnels.

Alt Text

What?? I didn’t catch a thing there!

So, all it does, it takes a port on your computer and forwards it to ngrok’s server. This port is linked to a public URL that can be accessed anywhere in the world by any device!

Wait! Isn’t it dangerous to do that?

Well, we should be safe if we stick to only testing APIs and debugging web apps. We can deploy any application/API on our localhost, expose it using ngrok and then turn it off. And for those who are really worried about security, ngrok has an option to create a password protected tunnel. On top of that, every tunnel is secured through the HTTPS protocol.

My favourite use cases (so far) ❤:

  • Test Web Apps using My Phone before deploying any code to the server
  • Debug OAuth integrations with external services
  • Many more! ❤

Top comments (3)

Collapse
 
devhammed profile image
Hammed Oyedele

Can you write something on this?

Collapse
 
mrtung profile image
Mr Tùng

OR using vhost + DDNS

Collapse
 
gugacavalieri profile image
Guga Cavalieri

Nice one Vitali, didn't know this one :)

Probably gonna check it out