skip to content
Just Change Direction

Exposing a local instance using a stable url

/ 2 min read

Correction - I have since found out that ngrok does support stable domains on the free plan (source)

Once you have set up the domain, you can use the following command to expose your local instance:

Terminal window
ngrok http --domain=<your-domain>.ngrok-free.app <port>

Original post below:


You have likely used ngrok before which allows you to expose your localhost instance to a real url on the internet. Ngrok is great, however, unless you pay for a plan the url changes each time you set it up. For some services this can be an issues and you need a stable url.

Turns out serveo is a great, free way to do this.

You can expose your local instance using the following command:

Terminal window
ssh -o ServerAliveInterval=60 -R <subdomain of your choice>:80:localhost:<local port> serveo.net
# for example
ssh -o ServerAliveInterval=60 -R myapp:80:localhost:3000 serveo.net

This will give you a stable url that you can use to access your local instance from anywhere. Using the example above the url will be http://myapp.serveo.net.

When you run the above command for the first time, you will need to authenticate with your Google or Github account. This saves the subdomain for your so no-one else can use it. After that, you can use the same command to expose your local instance.

You can then incorporate this steps into your package.json dev command to automatically do it in future:

{
"scripts": {
"dev": "ssh -o ServerAliveInterval=60 -R myapp:80:localhost:3000 serveo.net && next dev"
}
}