What you’ll need
- An ngrok account.
- Your ngrok auth token.
1. Install the ngrok Agent CLI
Run the command that corresponds to your operating system to install the Agent CLI:- Mac OS
- Debian Linux
- Windows
2. Connect your account
Connect your agent to your ngrok account by providing your auth token as shown below—replace$YOUR_TOKEN
with the string given to you in the dashboard.
3. Start your app or service
Start up the app or service you’d like to put online. This is the app that your agent endpoint will forward online traffic to. If you don’t have an app to work with, you can create a minimal app in your language of choice using the following code to set up a basic HTTP server at port8080
.
4. Put your app online
Start the ngrok agent by running the following command (replace8080
if your app is running on a different port).
All accounts come with a free dev domain that is automatically chosen when you start an endpoint. You can add the optional
--url
flag to customize this domain on paid plans.5. Secure your app
ngrok makes it simple to add authentication to your app by implementing a Traffic Policy. Using the Agent CLI, you can add a traffic policy to your endpoint by editing your ngrok config file, which was automatically created when you provided your auth token in step 3. Terminate the agent endpoint that you started up in step 5, then run the following command in your terminal to openngrok.yml
:
$YOUR_DOMAIN
, the agent endpoint should redirect the user to Google OAuth for authentication before proceeding to the app running on port 8080
.
ngrok.yml
This example uses ngrok’s default Google OAuth application.
To use your own, see the OAuth Traffic Policy Action documentation.
What’s next?
In this guide, you learned how to create an agent endpoint to forward traffic from the internet to an app running on your local device using the ngrok agent CLI. You were introduced to some of the most common commands you should know, and you implemented a traffic policy, which can be used for many kinds of actions beyond the basic authentication example here. You also saw how to edit your config file to make your agent endpoints repeatable and scalable by assigning a name you can refer back to with URLs, protocols, and actions already defined. What else can you do with these features?- If you need to interact with ngrok agent endpoints programmatically, we recommend using one of our Agent SDKs which are available for JavaScript (Node.js), Go, Python, and Rust.
- If your use case calls for a centrally managed, always-on endpoint instead of one that is only available when an agent is running, you should proceed to getting started with Cloud Endpoints.
- This quickstart barely scratches the surface of what’s possible with a traffic policy—check out the Actions overview to see what else you can do.
- Visit the Agent CLI command reference for a complete list of available commands.