|
| 1 | +# Create A Public URL For A Local Server |
| 2 | + |
| 3 | +At times while developing an app locally, you need to expose the local server |
| 4 | +to the public internet. This can be useful and necessary when working on a |
| 5 | +3rd-party integration or when you want to show what you have running locally to |
| 6 | +someone else. |
| 7 | + |
| 8 | +In addition to tools like [ngrok](https://ngrok.com/), I've found the |
| 9 | +[`localtunnel`](https://github.com/localtunnel/localtunnel) npm package to be |
| 10 | +an effective way to quickly expose a localhost port. |
| 11 | + |
| 12 | +``` |
| 13 | +$ npx localtunnel --port 3000 --subdomain some-custom-subdomain |
| 14 | +your url is: https://some-custom-subdomain.loca.lt |
| 15 | +``` |
| 16 | + |
| 17 | +This will create a `loca.lt` URL with the given subdomain that tunnels |
| 18 | +requests to `localhost:3000`. If the `--subdomain` flag is not specified or |
| 19 | +what you've specified isn't available, `localtunnel` will generate a random |
| 20 | +subdomain. |
| 21 | + |
| 22 | +For the subdomain, I recommend using something sufficiently unique like |
| 23 | +`josh-branchaud-04092021`. Using the date has the added benefit of |
| 24 | +contextualizing when I generated the URL. |
| 25 | + |
| 26 | +In my experience, these are not long-lived domains. Sometimes the connection |
| 27 | +gets interrupted and you'll have to restart it. Often when restarting, the |
| 28 | +specified subdomain will then be flagged as unavailable, so you have to tweak |
| 29 | +it a little. |
| 30 | + |
| 31 | +Because it is using `npx`, there is nothing to install as long as you already |
| 32 | +have `node` itself installed. |
0 commit comments