How to Find the Project Behind a Port on macOS Using lsof
A common problem for developers is opening localhost:3000 and finding the wrong app, since every dev server appears as node in process lists. The article explains that macOS lacks Linux's pwdx command, but lsof can reveal the working directory of the process listening on a given port. It walks through using lsof with the -sTCP:LISTEN flag to isolate the server, then the cwd descriptor to print the folder it was launched from. The guide also covers retrieving the full command line with ps, the start time, and the git branch, and offers a reusable shell function called whoport to combine these steps. It further notes that the same approach helps distinguish multiple worktrees or servers running in the same repository.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in