Ngrok offers several significant advantages for developers, especially when it comes to testing applications or hosting machine learning models. Ngrok allows you to expose local web applications behind NATs and firewalls to the public internet over secure tunnels. This is particularly useful for testing webhooks, APIs, and web applications without deploying them to a public server.

This guide will walk you through from downloading Ngrok to running your Flask app accessible through a public URL provided by Ngrok.
Prerequisites
- Python and Flask installed on your computer
- Basic knowledge of Flask web development
- A free account on Ngrok
Installing the Python Libraries
pip install flask pyngrok
Step 1: Download ngrok
- Visit the Ngrok website and sign up or log in.
- Navigate to the download section and select the version for Windows.
- Download the ZIP file.
- Copy the Auth Token and keep it seperately later this will be used to setup the ngrok.yml config file

Step 2: Extract the ZIP File
- Once downloaded, extract the ZIP file to a folder of your choice, such as
C:\ngrok\
. This folder will contain thengrok.exe
executable.
Step 3: Add ngrok Path to the Environmental Variable
For Windows users:
- Unzip the
ngrok
executable to a directory, e.g.,C:\ngrok\
. - Right-click on ‘This PC’ or ‘Computer’ on your desktop and select ‘Properties’.
- Click on ‘Advanced system settings’.
- Click on the ‘Environment Variables‘ button.
- In the ‘System variables’ section, find the ‘Path‘ variable and click ‘Edit’.
- Click ‘New’ and add the path to the directory where you unzipped
ngrok
(e.g.,C:\ngrok\
). - Click ‘OK’ to close the dialogs and apply the changes.

Now, ngrok
can be run from the command line regardless of the current directory.
Setting up the ngrok free domain
- Go to the Ngrok portal, navigate to Domains -> New Domain, and create your free domain.

Setting up the Ngrok Config File
- Open the command prompt in Windows.
- Enter the command
ngrok config edit
. - This opens the ngrok config file. Enter your Auth Token, Tunnel Name, hostname, and addr as follows:
authtoken: <Your Auth Token>
version: 2
tunnels:
flask:
proto: http
hostname: <your-chosen-hostname>.ngrok-free.app
addr: 127.0.0.1:5000
Replace <Your Auth Token>
with your actual Ngrok authentication token and <your-chosen-hostname>
with the hostname you’ve set up.
Creating a Simple Flask App
Create a simple Flask application as follows:
from flask import Flask
from pyngrok import ngrok
app = Flask(__name__)
@app.route("/")
def myportal():
return "Welcome to Marketcalls!"
if __name__ == '__main__':
# Setup ngrok
public_url = ngrok.connect(name='flask').public_url
print(" * ngrok URL: " + public_url + " *")
app.run()
This app will start a Flask server and make it accessible through an Ngrok URL.
Running Your Flask App
- Ensure you have
pyngrok
installed usingpip install pyngrok
. - Run your Flask app script. It will automatically start an Ngrok tunnel and print the public URL to the console.

Visit the provided URL in your browser to access your Flask application from anywhere

By following these steps, you’ve successfully hosted your Flask application using Pyngrok with an Ngrok free domain. This setup allows you to expose your local development server to the internet securely and conveniently, facilitating testing and sharing your work with others.