Skip to content

Instantly share code, notes, and snippets.

@RealYukiSan
Last active April 11, 2024 09:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RealYukiSan/1e0ad1fc07c41b26b0d54986f248ff09 to your computer and use it in GitHub Desktop.
Save RealYukiSan/1e0ad1fc07c41b26b0d54986f248ff09 to your computer and use it in GitHub Desktop.
run ngrok in background

start the program in background

setsid ngrok tcp <port> &>/dev/null </dev/null

optional, if you want store the log, enable ngrok option --log=stdout

parse the json string with node

node -pe 'JSON.parse(process.argv[1])' $(curl -s http://localhost:4040/api/tunnels)
# atau
curl -s http://localhost:4040/api/tunnels | node -pe 'JSON.parse(require("fs").readFileSync("/dev/stdin").toString())'
# atau
curl -s http://localhost:4040/api/tunnels | xargs -0 -I {} node -pe 'JSON.parse(JSON.stringify({}))'
# atau
curl -s http://localhost:4040/api/tunnels | xargs -0 -I {} node -pe 'JSON.parse(process.argv[1])' {}

setup tunnel to start multiple service

example ngrok config (ngrok config check):

version: "2"
authtoken: <redacted>
tunnels:
  ssh:
    addr: 22
    proto: tcp
  http:
    addr: 80
    proto: http

start multiple service with single tunnel:

ngrok start ssh http

reference

@RealYukiSan
Copy link
Author

get the ngrok configuration:

ngrok config check | awk '{print $NF}'
# or with grep
ngrok config check | grep -Eo '/[^ ]+$'
# or with cut
ngrok config check | cut -d ' ' -f 5-
# or with sed
ngrok config check | sed -n 's/Valid configuration file at //p'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment