Repository navigation
Description
Environment
- Nitro:
3.0.261029-rc - Node.js:
v26.13.0 - OS: macOS
Reproduction
-
Build a minimal Nitro application:
npx nitro build
-
Create
.envin the project root:PORT=14321
-
With neither
PORTnorNITRO_PORTexported in the shell, run:npx nitro preview
-
The server listens on port
3000. -
Pass the same variable through the process environment:
PORT=14321 npx nitro preview
-
The server now listens on port
14321.
Describe the bug
nitro preview loads environment files, but their PORT value does not apply to the preview listener.
Expected behavior: preview uses PORT from its loaded environment files when no --port flag or existing process environment variable overrides it.
Actual behavior: preview uses port 3000, despite .env defining PORT=14321. Supplying PORT through the shell works.
Additional context
The startup order appears to explain this behavior:
src/cli/commands/preview.tscreates thesrvxserver withmanual: true.- The
srvxNode adapter resolves and stores its listening port during construction. startPreview()subsequently loads environment files insrc/preview.ts.server.serve()starts listening using the previously resolved port.
manual: true delays listening, but does not delay port resolution.
For comparison, nitro dev correctly uses PORT from .env.
This report concerns preview's environment-loading order. The built server not automatically loading .env is documented behavior and is unrelated.
Logs
With `PORT=14321` in `.env`:
➜ Listening on: http://localhost:3000/ (all interfaces)
With `PORT=14321` supplied through the process environment:
➜ Listening on: http://localhost:14321/ (all interfaces)
Activity