What’s running on port 4000 on my Mac?
Port 4000 is a favorite of Elixir, Ruby static sites and GraphQL servers. If one of them refuses to start, something else from that list probably got there first.
Updated
Commonly used by
- Phoenix (Elixir)
mix phx.serverserves on 4000; generated apps readPORTin config/dev.exs. - Jekyll
bundle exec jekyll servepreviews your site on 127.0.0.1:4000. - Apollo Server
startStandaloneServerdefaults to 4000 for the GraphQL endpoint. - Hexo
hexo serverpreviews on 4000.
Check what’s on port 4000
lsof -nP -iTCP:4000 -sTCP:LISTEN
The command name points to the tool:
COMMAND | Likely |
|---|---|
beam.smp | Phoenix (the Erlang VM) |
ruby | Jekyll |
node | Apollo Server, Hexo, or any Node API |
For beam.smp and node, the working folder tells you which project it is:
lsof -a -p <PID> -d cwd -Fn | tail -1
With Stat Space: statspace port 4000.
Change the port
| Tool | How |
|---|---|
| Phoenix | PORT=4001 mix phx.server, or http: [port: 4001] in config/dev.exs |
| Jekyll | bundle exec jekyll serve --port 4001, or port: 4001 in _config.yml |
| Apollo Server | startStandaloneServer(server, { listen: { port: 4001 } }) |
| Hexo | hexo server -p 4001 |
Phoenix has a quirk worth knowing: if you started it with iex -S mix phx.server and closed the window without quitting the shell, the BEAM can keep running. Stop it with kill <PID>; it shuts down cleanly on SIGTERM.
Who can reach it
Phoenix’s generated dev config binds to {127, 0, 0, 1} and Jekyll binds to 127.0.0.1, so both are local by default. Jekyll’s --host 0.0.0.0 and Phoenix’s ip: {0, 0, 0, 0} open them to your network. Apollo Server and many plain Node servers listen on every interface unless you tell them otherwise. A GraphQL endpoint with introspection on hands anyone on the café Wi-Fi a map of your API. See dev server exposed to the network.
Seeing it live
Stat Space lists port 4000 with its project folder, the launcher that started it and its uptime, and warns if it’s on *:4000. Stopping it from the row asks first.
Questions
How do I run Phoenix on a different port?
Run PORT=4001 mix phx.server. That works because the generated config/dev.exs reads System.get_env("PORT"); if yours hardcodes port: 4000, edit it there.
Why does Jekyll say 'Address already in use - bind(2) for 127.0.0.1:4000'?
Another jekyll serve, often from another site folder, is still running. Stop it with kill <PID>, or run bundle exec jekyll serve --port 4001.
Is my GraphQL server on 4000 reachable from other devices?
Apollo's standalone server listens on all interfaces unless you pass a host, so check lsof. If it shows *:4000, anyone on the network can run queries against it.
Know what your Mac is doing, without adding to it.
Free, no account. Pro is $9.99 once for the first 100 buyers.