Scenario:
You're building a mobile app solo. The backend is ready, and now you're working on the UI. You run your server locally and try making requests from the appβnothing works.
Why? Your base URL (http://localhost:<port>
or http://127.0.0.1:<port>
) points to your local machine, but your mobile device has its own localhost.
Realizing this, you deploy your backend to a free online service, but then:
- The server shuts down after minutes of inactivity.
- Network requests are painfully slow.
Ngrok to the rescue π,
What is Ngrok?: Ngrok, is a tool that allows you expose your local server to the internet securely.
Getting Started
Head on to Ngrok - Signup
- Signup, and...
- Get your auth_token from the dashboard
MacOS:
brew install ngrok/ngrok/ngrok
ngrok config add-authtoken <your_auth_token>
Arch Linux
yay -S ngrok
ngrok config add-authtoken <your_auth_token>
Debian
wget https://bin.equinox.io/c/bNyj1mQVY4c/ngrok-stable-linux-amd64.deb
sudo dpkg -i ngrok-stable-linux-amd64.deb
ngrok config add-authtoken <your_auth_token>
What's Next
ngrok http http://127.0.0.1:<your-port>
Now ngrok will do it's thing π and give you the following results.
ngrok (Ctrl+C to quit)
Session Status online
Account your-email@example.com (Plan: Free)
Version 3.x.x
Region United States (us)
Latency 15ms
Web Interface http://127.0.0.1:4040
Forwarding https://random-subdomain.ngrok-free.app -> http://127.0.0.1:8000
Forwarding http://random-subdomain.ngrok-free.app -> http://127.0.0.1:8000
Connections ttl opn rt1 rt5 p50 p90
0 0 0.00 0.00 0.00 0.00
Add the following to your apps build configuration.
https://random-subdomain.ngrok-free.app
And you're set to go ππ
My Setup:
Ngrok Command:
Ngrok in action:
Conclusion
Ngrok is a game-changer when it comes to local development and testing. It eliminates the hassle of exposing your local server to the internet, making it easy to test APIs, webhooks, and mobile applications without deployment delays. With just a few commands, you get a secure, public URL that seamlessly tunnels traffic to your local machine.
Now, instead of struggling with localhost limitations or slow, unreliable free hosting, you can integrate Ngrok into your workflow and focus on building your app. π
Give it a try, and happy coding! π»π₯
Top comments (0)