Skip to main content
@ngrok/nextjs is a command that starts next dev and opens an ngrok endpoint to it as one process:
Stopping the command with Ctrl+C tears down both the endpoint and next dev, including the worker processes next dev starts. The command is built on the JavaScript SDK, so there’s no separate ngrok binary to install.
@ngrok/nextjs is published on npm at version 0.1.0 and maintained in the ngrok-samples/ngrok-nextjs repository.

What you’ll need

1. Set your auth token

Add your auth token to .env.local in your Next.js project root:
.env.local
The command reads .env.local itself, so you don’t need to export the variable in your shell. An NGROK_AUTHTOKEN already set in your shell takes precedence over the file.

2. Run your app

The command starts next dev on port 3000, opens an endpoint to it, and prints the public URL. To run on a different port, set PORT:

3. Test your endpoint

Open the printed URL in your browser. You see your Next.js app, served through ngrok. The command also:
  • Writes the public URL into .env.local as NEXTAUTH_URL and NEXT_PUBLIC_APP_URL, so auth libraries and client code pick it up automatically. The command leaves other lines in the file as they are.
  • Prints a QR code so you can open the URL on your phone. Set NGROK_QR=false to turn it off.
  • Prints a reminder, the first time you run it in a project, to register the URL with your OAuth and webhook providers.

Configuration

Create ngrok.config.ts (or .js or .mjs) in your project root to configure the endpoint:
ngrok.config.ts

Use your own domain

Set url to a domain you’ve reserved on your account. There are three places to set it, checked in this order:
  1. The NGROK_DOMAIN environment variable, in your shell or in .env.local. A bare domain gets https:// added for you.
  2. ngrok.config.local.ts, a personal config file with the same shape as ngrok.config.ts. Add it to .gitignore.
  3. ngrok.config.ts, the config file you commit and share with your team.
Keep a personal reserved domain out of the committed file when more than one person shares the ngrok account. Two people running the command against the same URL at the same time collide, and ngrok rejects the second with ERR_NGROK_334.

Multiple endpoints

To front more than one local service from a single command, such as the Next.js app plus a co-located API server, list them under endpoints:
ngrok.config.ts
Each entry takes the same fields as the root-level config plus upstream: a port number, which forwards to http://localhost:<port>, or any address string the JavaScript SDK accepts, such as https://localhost:8443. Entries under endpoints don’t write to .env.local unless you give them an env.url. Every endpoint needs its own url, or pooling: true on each endpoint that shares one. If two endpoints would share a URL without pooling, including two endpoints that both omit url and land on your dev domain, the command exits with an error before opening a session. Without that check, ngrok lets the most recently opened listener win and the other goes unreachable with no error.

Limits and availability

  • The command only parses ngrok.config.ts and ngrok.config.local.ts. It doesn’t read the agent config file.
  • NGROK_DOMAIN only applies to the endpoint that next dev runs on. Set url on each entry in endpoints directly.
  • An internal binding requires a URL that ends in .internal. ngrok rejects any other URL with ERR_NGROK_9029.
  • Endpoint counts and domains follow your plan’s limits. See free plan limits.

What’s next?