Directory Location
Portless automatically selects the state directory based on the proxy port:Non-Privileged Ports
Ports >= 1024 (default: 1355)Location:
~/.portlessUser-specific state. Each user has their own isolated state directory.Privileged Ports
Ports < 1024 (e.g., 80, 443)Location:
/tmp/portlessSystem-wide state. Shared between root and non-root processes to enable apps to register routes when the proxy runs as root.Why Different Directories?
Privileged ports (below 1024) require root access to bind. When you runsudo portless proxy start -p 80, the proxy process runs as root. If apps running as your regular user need to register routes, they must write to a shared location accessible by both root and non-root processes.
The solution: privileged ports use /tmp/portless (world-writable), while non-privileged ports use ~/.portless (user-specific).
Directory Contents
The state directory contains the following files:File Details
JSON array of active routes. Each route maps a hostname to a local port and process ID.Example:This file is watched by the proxy and automatically reloaded when changed. Apps add and remove routes by writing to this file with file locking.
Contains the port number the proxy is listening on (e.g.,
1355 or 80).Portless reads this file to discover which port to connect to when registering routes.Contains the process ID of the running proxy server.Used by
portless proxy stop to send a SIGTERM signal to the correct process.Marker file that exists when the proxy is running with HTTPS/TLS enabled.Portless checks for this file to determine whether to use
http:// or https:// URLs.Contains stdout and stderr from the proxy when running in daemon mode (the default).Useful for debugging if the proxy fails to start.
The local Certificate Authority (CA) certificate, generated on first use of HTTPS mode.This CA is added to your system trust store so browsers trust certificates issued by it.
Wildcard certificate for
*.localhost subdomains, signed by the local CA.This certificate is used by the proxy when serving HTTPS traffic.Overriding the State Directory
You can override the automatic directory selection using thePORTLESS_STATE_DIR environment variable:
- You want to isolate state for a specific project
- You need consistent behavior regardless of the proxy port
- You’re running in a containerized environment with specific mount points
State Discovery
When you runportless myapp npm start without the proxy running, Portless needs to discover whether a proxy exists and where its state is stored. The discovery process:
- Check
PORTLESS_STATE_DIR: If set, use that directory and readproxy.portfrom it - Check user directory (
~/.portless): Readproxy.portand verify the proxy is actually listening - Check system directory (
/tmp/portless): Readproxy.portand verify the proxy is listening - Fall back: Use the default port (from
PORTLESS_PORTor 1355) and select the appropriate directory
Multi-User Considerations
When using privileged ports with/tmp/portless:
- The directory and files are created with permissions allowing both root and non-root access
- Apps running as different users can all register routes
- File locking prevents race conditions when multiple apps modify
routes.jsonsimultaneously - The proxy automatically fixes file ownership after writing to ensure non-root processes can read them
Cleaning Up
To remove Portless state:/etc/hosts: