DEV Community

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

How to access your localhost application on any device

Guga Cavalieri
Software Engineer @ Kudos linux and open-source software enthusiast 🧡 contributor @freeCodeCamp ⛺
・1 min read

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! ❤

Discussion (6)

vitalipom profile image
Vitali Pomanitski

Public Internet?????? Just use CharlysProxy....

devhammed profile image
Hammed Oyedele

Can you write something on this?

vitalipom profile image
Vitali Pomanitski

Yeah, I will elaborate on it over time

vitalipom profile image
Vitali Pomanitski

CharlesProxy allows you to create a local LAN domain over your WiFi or lan network just like it's in the internet. Again, please don't expose your computer to public internet. For ANY reason.

gugacavalieri profile image
Guga Cavalieri Author

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

Probably gonna check it out

mrtung profile image
Mr Tùng

OR using vhost + DDNS