Skip to content

feat: auto-shift port when default is in use (Vite-style) - #14

Merged
melvincarvalho merged 1 commit into
gh-pagesfrom
feat-port-hopping
May 16, 2026
Merged

melvincarvalho merged 1 commit into
gh-pagesfrom
feat-port-hopping

Conversation

@melvincarvalho

Copy link
Copy Markdown
Contributor

Summary

If 5444 is already taken (another jspod running, dev server collision, whatever) jspod previously crashed on JSS bind. Now jspod probes the requested port and shifts up by one — up to 10 attempts — finding the first free port and printing a clear line before the banner:

```
Port 5444 is in use, using 5445 instead.
```

Mirrors Vite / Next.js dev-server behaviour. Solves the most common "I already have jspod running" friction.

Implementation

Adds a small findFreePort(startPort, host) helper using `net.createServer().listen(port, host)` — bind succeeds → free, EADDRINUSE → take the next one. Probes against the same host JSS will bind to so the answer reflects reality.

After CLI parse, before banner display, jspod calls `await findFreePort(options.port, options.host)`. If the returned port differs from the requested one, prints the yellow warning. If no free port in the 10-port range, exits with a clear error pointing at `--port`.

Test plan

  • First jspod takes 5444 (default)
  • Second jspod auto-shifts to 5445, prints the warning line, banner shows 5445
  • Both bound concurrently (verified via ss -tlnp)
  • Manual after merge + publish 0.0.16: npx jspod@0.0.16 while another jspod is running; confirm the shift + browser auto-opens to the right port

Refs #1

If the requested port is busy, probe up to 10 ports above it
(net.createServer-based bind test on the same host JSS will use)
and use the first free one. Print a clear "Port 5444 is in use,
using 5445 instead." line if shifted. Errors with a hint to pass
--port if no slot is free in the range.

Mirrors Vite/Next.js dev-server behaviour. Solves the most common
"jspod already running" friction without forcing the user to read
an error and retry with --port.

Bumps jspod to 0.0.16.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant