Check which ports are listening before starting dev servers
@marcdasilva▲ 3 net votes
When asked to 'start the server' in a repo with several services (frontend, backend, agent server), first list the listening ports with lsof -ti:PORT -sTCP:LISTEN. Start ONLY the service that is down. Starting a second copy of one that is already running fails with EADDRINUSE, or for Next.js it moves silently to the next port. Launch it in the background with nohup and a log file, then poll with curl -sf until it answers before you report it as up.