DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations

Using Config Files With ngrok

Want to learn more about using ngork? Check out this tutorial on how to use config files with ngork for testing locally on your applications.

Lorna Mitchell user avatar by
Lorna Mitchell
·
Aug. 14, 18 · Tutorial
Like (1)
Save
Tweet
Share
11.88K Views

Join the DZone community and get the full member experience.

Join For Free

I'm a huge fan of ngrok. Ngrok is a tool that can create a secure tunnel to your laptop. It is brilliant for testing, well, anything running locally. Someone asked me about my setup recently, and I'm using a couple of config files to keep things quick and consistent, so I thought I'd share here what I shared with them.

You can use a central config file for ngrok and/or specific config files for each project. I use both, so I'll demonstrate my setup.

Main Config File

The main config file for ngrok is probably the right place for most settings. When you log in, your auth token is stored here. I also have my region set to eu since that's where my servers and I are normally located; the default value here is us.

Also, in this config file, I have two tunnels defined:

authtoken: Redacted
region: eu

tunnels:
    ljnexmo:
        proto: http
        addr: 8080
        hostname: ljnexmo.eu.ngrok.io
    test:
        proto: http
        addr: 8080
        subdomain: f85c1a3f


I do have tunnels configured here, but I don't always use these with ngrok. I work in multiple server-side languages and their "usual" port numbers all differ, so I'm as likely to start a tunnel with ngrok http --subdomain=f85c1a3f 3000. The tunnel configs are very handy, especially for a setup that needs more settings than these or that you will need to use over and over.

A great example of a tunnel that I've used a lot is one used in my book, PHP Web Services. Ngrok config files can only be in one region or another, so I used a separate config file for this, which lives in the same directory as the code examples. It looks like this:

region: us

tunnels:
    phpwebservices:
        proto: http
        addr: 8080
        subdomain: 29baf15


In real life, using a per-project config like this is super helpful. It keeps things together, especially if different projects want to take advantage of different regions.

To use this tunnel, my command looks like this:

ngrok start --config=ngrok-phpws.yml phpwebservices


I do tend to reserve the domains I'm using since I have a paid account with ngrok. You can see a few places where I started using a domain and then realized I'd better reserve it!

Pro-tip: Even without a paid account, you can request a specific subdomain when starting your tunnel. If it's available then, you can use it. This is super helpful when restarting tunnels during a project — it saves time updating URLs everywhere!

Related Posts

  • PHP Web Services: 2nd Edition
  • Test Incoming Webhooks Locally with Ngrok
  • Use Ngrok Dashboard from VM

Published at DZone with permission of Lorna Mitchell, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • All the Cloud’s a Stage and All the WebAssembly Modules Merely Actors
  • Developer Productivity: The Secret Sauce to Building Great Dev Teams
  • LazyPredict: A Utilitarian Python Library to Shortlist the Best ML Models for a Given Use Case
  • High-Performance Analytics for the Data Lakehouse

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: