Environment port not used on a local PC

When I execute pnpm dev, the website loads under port 3000 (seems like the default one) but the .env have explicity PORT=3500 NODE_ENV=development ..... also I checked the /src/env.js and I cannot see anything related to the PORT I only have .env file under windows 10 with nodejs 20.1X what I'm doing wrong? how can I expose the server to another port? also the file react.tsx have this function getBaseUrl() { if (typeof window !== "undefined") return window.location.origin; if (process.env.VERCEL_URL) return https://${process.env.VERCEL_URL}; return http://localhost:${process.env.PORT ?? 3000}; }
No description
1 Reply
sabraman
sabraman2mo ago
you can add to your package.json: universal way "dev:port": "node -e \"process.env.PORT=require('dotenv').config().parsed.PORT;require('next/dist/bin/next')\" dev", if you are using windows (why? just use wsl) "dev:port:win": "pwsh -c \"next dev -p ((gc .env)-match'PORT=(.+)'-replace'.*=')\"", and for linux/macos "dev:port:unix": "next dev -p $(grep PORT .env | cut -d '=' -f2)", and if you just want to set port to 3500 and not getting it from .env, you could just change "dev: next dev -p 3500"

Did you find this page helpful?