Getting Started

Portless replaces port numbers with stable, named .localhost URLs for local development. For humans and agents.

- "dev": "next dev"                  # http://localhost:3000
+ "dev": "portless myapp next dev"   # https://myapp.localhost

Install

Global (recommended):

npm install -g portless

Or as a project dev dependency:

npm install -D portless

portless is pre-1.0. Pin the version per project with npm install -D portless (locked by your lockfile) or record it in a version manager config such as .tool-versions for global installs, so contributors stay on the same release. State directory format changes between releases can require running portless trust again.

Run your app

Just run portless. It reads the "dev" script from package.json and runs it through the proxy:

portless
# -> runs "dev" script, https://<project>.localhost

The app name is inferred from package.json, git root, or directory name. Use a portless.json to override (e.g. { "name": "myapp" } for https://myapp.localhost). --quiet or PORTLESS_QUIET=1 hides startup status lines, including the banner, proxy running status, name, hostname, prefix, assigned port, and Running: line. App URLs, warnings, errors, proxy startup output, and monorepo URL tables remain visible. Use --no-stdin when the wrapped command has its own stdin handler.

You can also run with an explicit command:

portless myapp next dev
# -> https://myapp.localhost

HTTPS with HTTP/2 is enabled by default. On first run, portless generates a local CA, trusts it, and binds port 443 (auto-elevates with sudo on macOS/Linux). Use --no-tls for plain HTTP.

The proxy auto-starts when you run an app. A random port (4000--4999) is assigned via the PORT environment variable. Most frameworks (Next.js, Express, Nuxt, etc.) respect this automatically. For frameworks that ignore PORT (Vite, VitePlus, VitePress, Astro, React Router, Angular, Expo, React Native, Wrangler), portless auto-injects the right --port flag and, when needed, a matching --host flag (--ip for Wrangler). Injection reaches through a package script whose command starts with the framework or a known runner ("dev": "vite", "dev": "bunx vite"). Only the framework's server commands get the flags (dev, serve, preview, start, a bare vite, or vite [root]); a command that does not serve, such as vite build, vite optimize, vp test or astro check, rejects them and is left alone. Expo connection modes (--localhost, --lan, --tunnel) are preserved while the assigned port is still injected. A script portless cannot classify is left alone too: a flag before the subcommand on a CLI whose flag grammar it does not track (vp --mode dev build). Portless also leaves a script alone when appending flags to it would not work: a compound command (&&, |, ;), a trailing # comment, its own -- option terminator, an env prefix (NODE_ENV=production vite), delegation to another script ("dev": "npm run dev:vite"), or runner flags before the script name (bun run --bun dev). Those keep their own port, so set it in the script yourself. At a workspace root that uses Turbo, Turbo starts each package script itself, so portless sets PORT and HOST but adds no flags. Read them in the framework config (for Vite, set server.port and server.host from process.env), or set "turbo": false in the root portless configuration so portless starts the apps and adds the flags.

Use in package.json

Your scripts stay clean:

{
  "scripts": {
    "dev": "next dev"
  }
}

Then run portless or portless run to go through the proxy. Use portless get <name> --json when a script needs the name, hostname, and URL. The output includes port when an active route matches the resolved hostname. portless completion <bash|zsh|fish> prints a shell completion script.

You can also use portless directly in scripts:

{
  "scripts": {
    "dev": "portless myapp next dev"
  }
}

Subdomains

Organize services with subdomains:

portless api.myapp pnpm start
# -> https://api.myapp.localhost

portless docs.myapp next dev
# -> https://docs.myapp.localhost

Referencing another app

In a monorepo run, every proxied app receives PORTLESS_URL_<APP> for every proxied app, so services can call each other without hardcoded ports. api.myrepo becomes PORTLESS_URL_API_MYREPO: the base name uppercased with dots and hyphens replaced by underscores. The name is stable across git worktrees while the value carries the worktree prefix.

Outside a monorepo run, use portless get <name> or eval "$(portless env API_URL=api)".

Git Worktrees

portless run automatically detects git worktrees. In a linked worktree, the branch name is prepended as a subdomain so each worktree gets its own URL without any config changes:

# Main worktree (no prefix)
portless run next dev   # -> https://myapp.localhost

# Linked worktree on branch "fix-ui"
portless run next dev   # -> https://fix-ui.myapp.localhost

Put portless run in package.json to apply these naming rules in each checkout.

Repeat --name to serve one dev server on multiple hostnames. Each name gets the worktree prefix or configured worktree.hostnameTemplate, and the first name sets PORTLESS_URL and receives any tunnel. Use --name to override the inferred base name while keeping the worktree prefix:

portless run --name myapp next dev   # -> https://fix-ui.myapp.localhost

Use --prefix <label> (or PORTLESS_PREFIX) to set the label yourself, with "" for none. See Configuration to change the label style or the whole hostname.

Custom TLD

By default, portless uses .localhost which auto-resolves to 127.0.0.1 in most browsers. If you prefer a different TLD (e.g. .test), use --tld:

portless proxy start --tld test
portless myapp next dev
# -> https://myapp.test

The proxy auto-syncs /etc/hosts for route hostnames, so .test and other dev hostnames resolve on your machine. If a route hostname will not resolve, the command that registered it warns instead of failing silently and points you to portless hosts sync. Note that .localhost names resolve without a hosts entry on current macOS and Linux, so a skipped write is often invisible; a custom TLD needs the entry.

Repeat --tld to serve the same app names under multiple TLDs from one proxy:

portless proxy start --tld localhost --tld test
portless myapp next dev
# -> https://myapp.localhost
# -> https://myapp.test

When multiple TLDs are configured, PORTLESS_URL uses the first TLD. PORTLESS_TLD accepts the same comma separated list format, e.g. PORTLESS_TLD=localhost,test.

The --tld value accepts a lowercase DNS name such as dev.example.com, so a domain you own can be used as the "TLD":

portless proxy start --tld dev.example.com
portless myapp next dev
# -> https://myapp.dev.example.com

This gives local URLs the same structure as production, which keeps OAuth redirect URIs, cross-subdomain cookies, and host-based routing working the same way in both environments. Strict OAuth providers such as Google and Apple reject .localhost and .test redirect URIs but accept a real domain, so https://myapp.dev.example.com/api/auth/callback/google works as a redirect URI. Each label must follow DNS rules: lowercase letters, digits, and interior hyphens, with at most 63 characters per label and 253 characters total. The full hostname (app.TLD) is also subject to the 253-character limit.

A custom TLD is reachable only from the machine running the proxy, because outside LAN mode the proxy binds only to loopback. LAN mode serves apps under .local and ignores a custom --tld, so the two can't be combined.

Recommended: .test (IANA-reserved, no collision risk). Avoid .local (conflicts with mDNS/Bonjour) and .dev (Google-owned, forces HTTPS via HSTS).

How it works

Portless runs an HTTPS reverse proxy on port 443 by default. Each app registers a route mapping its hostname to an assigned port. Requests to https://<name>.localhost are proxied to the app.

The proxy listens only on the IPv4 and IPv6 loopback addresses, 127.0.0.1 and ::1, by default. Network interfaces are exposed only when LAN mode is explicitly enabled.

Browser (myapp.localhost) -> proxy (port 443) -> App (random port)

When portless itself returns an error, it sets X-Portless: 1 and Vary: Accept. Portless generates 404 (not_found) for an unknown host, 408 (request_timeout) when a client stops sending a request body for more than 15 seconds, 421 (misdirected_request) for a misdirected request, 502 (bad_gateway) when the app is unreachable, 503 (service_unavailable) when a request waits more than 30 seconds in the per-backend queue or the queue reaches 512 waiting requests, 504 (gateway_timeout) when the backend takes more than 120 seconds to send response headers after the request upload finishes, and 508 (loop_detected) for a request loop. Browsers get an HTML page, while any client whose Accept header does not include text/html, such as curl or fetch, gets a JSON body such as {"error":"bad_gateway","upstream":"myapp.localhost","message":"..."}. To distinguish a proxy-generated 408, 503, or 504 from an app response, check for Vary: Accept and a JSON body with upstream and an error of request_timeout, service_unavailable, or gateway_timeout, or a portless HTML error page. Responses from your own app are forwarded unchanged. Hostnames outside the portless TLDs, such as a site a DNS blocklist points at 127.0.0.1, never get the app list. Over HTTPS with portless's generated certificates, portless refuses to present a certificate for them, so the TLS handshake fails. With a custom --cert and --key, on a plain HTTP proxy, or over HTTPS when only the Host header names such a host, the request gets 421 Misdirected Request.

When no app is registered under portless.localhost (or portless.<tld> when a custom TLD resolves to the proxy), opening that hostname serves an active-routes dashboard (HTML by default, or JSON with Accept: application/json; over HTTPS with generated certificates, use a configured TLD). Active app links on the 404 page preserve the request path and query string, omitting the trailing slash for /.

Proxy between portless apps

If your frontend dev server proxies API requests to another portless app, make the dev server proxy rewrite the Host header. Without it, portless routes the request back to the frontend in a loop, and responds with 508 Loop Detected and a message pointing to this fix.

Vite (vite.config.ts):

server: {
  proxy: {
    "/api": {
      target: "https://api.myapp.localhost",
      changeOrigin: true,
      ws: true,
    },
  },
}

webpack-dev-server (webpack.config.js):

devServer: {
  proxy: [{
    context: ["/api"],
    target: "https://api.myapp.localhost",
    changeOrigin: true,
  }],
}

Requirements

  • Node.js 24+
  • Bun 1.4.4+ (optional, required when running the HTTPS proxy under Bun)
  • macOS, Linux, or Windows