Using ngrok as an external process

I don’t know why it took me so long to figure this out but it turns out that the ngrok client has an api that you can access locally. That means you can run ngrok external to your process and then call to it to get the public tunnel information. This is very handy as ngrok doesn’t really like starting and stopping as rapidly as you may want while developing a server.

This means rather than using the ngrok package on npm for your local development, look towards docker hub:

I added an entry to my docker-compose.yml file like so:

version: '3'
    image: wernight/ngrok
      - 4040:4040
      NGROK_PORT: 4000
      NGROK_PROTOCOL: http

Next in your code, after staring the containers, simply call the service from your application code:

const { status, data } = await axios.get('http://localhost:4040/api/tunnels')
const { tunnels } = data
const { public_url } = tunnels.find(t => t.proto === 'https')
this.publicEndpoint = public_url

The ngrok tunnel will stay alive as your server restarts over and over.

Author: justinmchase

I'm a Software Developer from Minnesota.

Drop a brain bomb

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.