Use Ngrok in Your Rails Project

Josh-Gotro
The Startup
Published in
2 min readOct 25, 2020

I was recently working on a project that needed to connect web sockets to a deployed database in order to work. This was a sprint and I just needed to get the database up quickly.

Enter Ngrok.

Spend more time programming. One command for an instant, secure URL to your localhost server through any NAT or firewall. — ngrok.com

It says it right on their website… but is it too good to be true?

Install Ngrok

Installation instructions through their site are straightforward, but if you have Homebrew installed already then it’s even simpler.

Run the following from your terminal:

brew cask install ngrok

Side note, TIL that whilebrew is the standard way of using the package manager, brew cask extends the functionality and generally focuses on GUI programs. Check ’em out here.

You can go to their site and create an account to get some more features and longer session times. But if you GOTTA GO FAST you can just skip account creation and start using it right away.

No time to setup an account today.

Connect to localhost

ngrok http <port>

replace <port> with whatever localhost you have configured in your backend. Rails defaults to 3000, but you should use whatever you want.

That’s it

connected

Use either the http or https just like you would localhost including any routes you have set up.

ex: If you have http://localhost:3000/users setup, you can use http://7b9d64a72a89.ngrok.io/users or https://7b9d64a72a89.ngrok.io/users

Where else can you use Ngrok?

  • Someone shared a blog post where the author used Ngrok to help wrangle the infamous Active Storage.
  • You could help a friend troubleshoot their database remotely. (or get help from a friend…)

If you have another idea tell me in the comments :)

Check out some of my other stories; Form Validations & React Hooks, or Recoil.js & simple global state. Contact me at joshuagauthreaux@gmail.com or through joshgotro.com.

Thank you for reading and be well!

--

--

Josh-Gotro
The Startup

Hi, I’m Josh Gauthreaux. I’m a full-stack web developer from Austin, TX. I love people and I love building things.