Portmoleby techynARDownload

How to run a dev server on a different port

By techynAR · Updated

Short answerMost dev servers take a port flag: vite --port 3001, next dev -p 3001, ng serve --port 4201, flask run -p 5001, rails s -p 3001, python manage.py runserver 8001. Create React App and many Node servers read the PORT environment variable instead.

Command line flags

Environment variable

PORT=3001 npm start

Create React App, Express apps that read process.env.PORT, and many hosting-style servers use PORT. In a package.json script, prefix it the same way, or use the cross-env package if your team also uses Windows.

Make it permanent

Put the port in the config file instead of typing it each time: server.port in vite.config.ts, PORT in .env, or the --port flag in the package.json script. That way two projects never fight over the default.

Restarting on a new port in one step

Portmole Pro's Change port button works out the right flag for your framework, shows you the new command for review, stops the old server and starts it again on the new port, in the same folder.

Frequently asked questions

How do I change the port in Vite?

Run vite --port 3001 or set server: { port: 3001 } in vite.config.ts.

How do I run Next.js on a different port?

Use next dev -p 3001, or set the PORT environment variable.

How do I change the Django development server port?

Pass it after runserver: python manage.py runserver 8001.

Skip the terminal

Portmole shows every port your Mac is listening on and closes any of them with one click. Free, signed and notarized, about 7 MB.

Download Portmole for Mac

Keep reading