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
andUDP
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:
- Download and Install
ngrok
: Visit the ngrok website and download the version compatible with your operating system. - You will need to
sign up
for a freengrok account
to use it. After signing up, you'll get anauthentication token
that you’ll need to set up the service. - Connect Your Account:
Run the following command to add your auth token (replace
YOUR_AUTH_TOKEN
with the token you got from yourngrok
dashboard):ngrok authtoken YOUR_AUTH_TOKEN
- Expose Your
Local Server
: Now thatngrok
is set up, you can expose yourlocalhost
to the world. Assuming you have alocal server
running on port3000
, you can startngrok
with the following command:
Thisngrok http 3000
command
will create apublic URL
that forwards requests to your local server. For example, you might get a URL like https://abcd1234.ngrok.io. ThisURL
can now be accessed from anywhere in the world.