Serve: Why not `localhost:3000`?

Created on 25 Jan 2017  路  8Comments  路  Source: vercel/serve

@leo I ended up here because I previously used TJ's serve, which ran on localhost:3000. Can you explain your intent behind using 192.168.0.40:<random> instead?

Copying to clipboard is a nice feature that mitigates some of the pain there, but it's easier to get someone up and running with a codebase that uses serve by telling them to just open a browser to e.g. localhost:3000 than to say "npm start, then paste into a new browser window.

Also, running on a random port means that every time you restart, you can't just refresh your browser -- you have to paste in the new address.

I guess I'm mostly responding to having my usual workflow changed just because I npm install served in a new project and was surprised by the changes.

Most helpful comment

Might help to mitigate your issue: serve -p 3000

All 8 comments

Also, running on a random port means that every time you restart, you can't just refresh your browser -- you have to paste in the new address.

You'd usually keep this server running, while your code bundler/build system will rebuild your bundles.

Might help to mitigate your issue: serve -p 3000

Exactly! @derhuerst @timneutkens 馃槉

@derhuerst yes, but sometimes you need to restart...it's a minor ergonomic issue, just wondering about the reasoning behind the change.

@timneutkens I already added that to my npm script, again just wondering why the setup here is different than in the previous version of serve (pre 2.0). It amounts to an API change, essentially. I can adapt, just wondering why @leo et al. didn't try to maintain the previous workflow.

yes, but sometimes you need to restart

when?

it's a minor ergonomic issue, just wondering about the reasoning behind the change.

Using random ports is in many cases very sensible, as starting the server would usually fail binding a port already used. From what it seems, the setup at now.sh is geared towards random ports.

@derhuerst when I make changes to files that are not watched; when my watcher doesn't catch changes due to setup omissions; when i restart my computer and Chrome reopens tabs. It's not common but it's not a fabricated scenario, either.

Interesting you mention failing binding to a port already in use. I had a conflict on port 3000 as I was trying to get serve working, in fact. However, serve seems to fail silently in this case -- the console shows no indication the port is in use. Can open a separate issue if that is actually a bug. Thanks for the now.sh example, makes sense.

However, serve seems to fail silently in this case -- the console shows no indication the port is in use. Can open a separate issue if that is actually a bug.

Cannot confirm on master.

@derhuerst just tested again and now I see an EADDRINUSE error, so feel free to ignore :D

Was this page helpful?
0 / 5 - 0 ratings

Related issues

fabricionaweb picture fabricionaweb  路  3Comments

xiyuyizhi picture xiyuyizhi  路  5Comments

Olexiy665 picture Olexiy665  路  3Comments

phelma picture phelma  路  5Comments

gaearon picture gaearon  路  4Comments