ngrok Environment

Nextjournal is a great way to experiment with building services in the cloud. Ngrok makes it easy to expose localhost servers to the internet.

Install ngrok.

curl -sS https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip -o ngrok.zip
unzip /ngrok.zip
3.0s
ngrok-environment (Bash)

Settings for the ngrok configuration file.

region: us
console_ui: true
tunnels:
  btf:
    proto: http
    addr: 5000
    subdomain: btf
ngrok.yml
YAML

Grab your authtoken from ngrok. The token will authenticate this notebook with the ngrok service.

Store the token in your Nextjournal secret vault and add it to the environment.

Prepend the authtoken to the configuration file above, ngrok.yml.

echo 'authtoken:' $ngrok | cat - ngrok.yml > /tmp/out && mv /tmp/out ngrok.yml
0.6s
ngrok-environment (Bash)

Run ngrok in the background using nohup. Unfortunately, there are no plans to offer a daemon service in the basic ngrok package.

nohup /ngrok start --all --config="/ngrok.yml" &> /tmp/ngrok.log & sleep 1
tail /tmp/ngrok.log
1.7s
ngrok-environment (Bash)

Place the URL into a browser and the tunnel will be visible. Anything served from port 5000 will appear here. In this case, there is nothing being served, hence the error message.

The service is up and running. To stop the ngrok tunnel, use the kill command with the process ID: kill <PID> or kill -9 "$(pgrep ngrok)".

ps aux
0.8s
ngrok-environment (Bash)
kill -9 "$(pgrep ngrok)"
0.9s
ngrok-environment (Bash)
ps aux
1.4s
ngrok-environment (Bash)
Runtimes (1)