Portless assigns apps a random port (4000-4999) and sets theDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/vercel-labs/portless/llms.txt
Use this file to discover all available pages before exploring further.
PORT and HOST environment variables. Most frameworks respect these variables automatically. For frameworks that ignore PORT, portless auto-injects the correct CLI flags.
Frameworks That Respect PORT
These frameworks work automatically with portless - no special configuration needed:
- Next.js - Reads
PORTandHOSTenvironment variables - Express - Standard Node.js server respects
PORT - Nuxt - Reads
PORTandHOSTfrom environment - Remix - Uses
PORTfor dev server - NestJS - Respects
PORTenvironment variable - Fastify - Standard Node.js server behavior
- Koa - Standard Node.js server behavior
- SvelteKit - Uses Vite under the hood (handled by auto-injection)
- Hono - Respects
PORTenvironment variable - Most Node.js servers - Standard convention
Frameworks That Need Flag Injection
These frameworks ignore thePORT environment variable and require CLI flags. Portless detects these commands and automatically injects the correct flags:
Vite
Detection: Command starts withvite
Injected flags:
--port <port>- Sets the port--strictPort- Prevents Vite from picking a different port if the assigned one is in use--host 127.0.0.1- Binds to IPv4 localhost (portless proxy connects via 127.0.0.1)
- SvelteKit (
vite dev) - Solid Start
- Qwik
- Analog (Angular + Vite)
Astro
Detection: Command starts withastro
Injected flags:
--port <port>--host 127.0.0.1
--strictPort, so the port may change if unavailable.
Example:
React Router (v7+)
Detection: Command starts withreact-router
Injected flags:
--port <port>--strictPort--host 127.0.0.1
Angular
Detection: Command starts withng
Injected flags:
--port <port>--host 127.0.0.1
--strictPort.
Example:
Expo
Detection: Command starts withexpo
Injected flags:
--port <port>--host localhost(Expo requireslocalhostinstead of127.0.0.1)
React Native
Detection: Command starts withreact-native
Injected flags:
--port <port>--host 127.0.0.1
How Auto-Injection Works
TheinjectFrameworkFlags function in cli-utils.ts inspects the command basename and appends flags before spawning the process:
- Flags are only injected if not already present in the command
- Only the command basename is checked (e.g.,
/usr/local/bin/vitematchesvite) - The
PORTenvironment variable is still set even when flags are injected
Environment Variables
Portless sets these environment variables for all child processes:PORT- The assigned port (e.g.,4123)HOST- Always127.0.0.1PORTLESS_URL- The public-facing URL (e.g.,http://myapp.localhost:1355)
PORT will use it automatically. Frameworks that ignore it will receive the injected flags instead.
Custom Frameworks
If your framework ignoresPORT and is not in the auto-injection list, you have two options:
Option 1: Pass Flags Manually
Use thePORT environment variable in your command:
$PORT is correctly substituted.
Option 2: Use a Wrapper Script
Create a script that readsPORT and passes it to your framework:
Disabling Auto-Injection
If you want to bypass portless entirely and run the command normally:Forcing a Specific Port
If you need a fixed port instead of the auto-assigned range (4000-4999):Strictness Behavior
Some frameworks support “strict port” mode, which causes the server to fail if the port is unavailable:- With
--strictPort(Vite, React Router): Portless guarantees the assigned port is used or the server exits with an error - Without
--strictPort(Astro, Angular): The framework may silently pick a different port if the assigned one is busy
- Finding a free port immediately before spawning
- Using a random-first search strategy (tries 50 random ports before scanning sequentially)
IPv4 vs IPv6
Portless connects to apps via127.0.0.1 (IPv4). Some frameworks default to ::1 (IPv6), which would cause connection failures. To prevent this, portless injects --host 127.0.0.1 for frameworks that need it.
Exception: Expo requires --host localhost instead of an IP address.
Contributing New Framework Support
If you use a framework that ignoresPORT and isn’t in the auto-injection list, you can add it to FRAMEWORKS_NEEDING_PORT in cli-utils.ts:
strictPort: true if the framework supports a flag that prevents it from silently choosing a different port.