How to Share Your Local Server Online Using ngrok for Testing & Collaboration

Exposing Your Local Server to the Internet with ngrok

Exposing Your Local Server to the Internet with ngrok

secure tunnels
expose localhost
dev tools
localhost to internet
ngrok
remote access
testing webhooks

In the world of software development, especially when you're building web applications, testing locally is essential. However, there are times when you want to expose your local server to the internet for testing, collaboration, or even demonstrating your work. This is where ngrok comes into play. It allows you to create a secure tunnel from your local machine to the internet, giving you a globally accessible IP address (or URL) for your localhost server.

For my IMPATIENT reader

You can expose your local server to the internet by running this command after installing and configuring ngrok

ngrok http 3000

Here 3000 is the port number of your local server

What is ngrok?

Ngrok is a reverse proxy that creates a secure tunnel between a publicly accessible URL (or IP address) and your localhost. This allows you to share your local development environment with anyone on the internet. It is particularly useful when you want to test APIs, webhooks, or mobile apps that require a public endpoint.

Key Features

  • Expose a local web server to the internet over HTTPS.
  • Access logs of traffic passing through your tunnel.
  • Forward TCP and UDP connections.
  • Provides secure tunneling.

How to Use ngrok to Expose Your Localhost

Setting up ngrok to expose your localhost is straightforward. Here's how you can do it:

  1. Download and Install ngrok: Visit the ngrok website and download the version compatible with your operating system.
  2. You will need to sign up for a free ngrok account to use it. After signing up, you'll get an authentication token that you’ll need to set up the service.
  3. Connect Your Account: Run the following command to add your auth token (replace YOUR_AUTH_TOKEN with the token you got from your ngrok dashboard):
    ngrok authtoken YOUR_AUTH_TOKEN
  4. Expose Your Local Server: Now that ngrok is set up, you can expose your localhost to the world. Assuming you have a local server running on port 3000, you can start ngrok with the following command:
    ngrok http 3000
    This command will create a public URL that forwards requests to your local server. For example, you might get a URL like https://abcd1234.ngrok.io. This URL can now be accessed from anywhere in the world.