npm run dev still running after closing Terminal
You closed the tab, or the editor, or pressed Ctrl-Z by mistake, and the next npm run dev says the port is taken or quietly moves to 3001. The old server is still alive. Here’s how to find it, why it happens and how to stop it from happening.
By Anmol Sethi · Updated
In short
List the node servers still listening with lsof -nP -iTCP -sTCP:LISTEN | grep node, check which project each is with lsof -a -p <PID> -d cwd, then kill <PID>. They survive when the process was suspended with Ctrl-Z, when a wrapper like npm was force-killed and its child kept running, or when the terminal closed without sending a stop.
Find the leftover servers
lsof -nP -iTCP -sTCP:LISTEN | grep -E 'node|bun|deno'node 61504 you 23u IPv6 TCP *:3000 (LISTEN)
node 61877 you 21u IPv6 TCP [::1]:5173 (LISTEN)node doesn’t say which project. Its working folder does:
lsof -a -p 61504 -d cwd -Fn | sed -n 's/^n//p'
ps -o pid,ppid,stat,etime,command -p 61504etime is how long it’s been running. A PPID of 1 means the process that started it is gone: nothing will ever stop it but you.
Stop it
kill 61504Give it a second, then check the port is free with the lsof line above. If it’s still there, kill -9 61504. To stop every Vite or Next.js dev server at once, match the command line:
pkill -f 'vite|next dev'pkill -f matches anything with those words in its command line. Run pgrep -fl 'vite|next dev' first to see what it would stop.
Why it keeps running
| What happened | What’s left | How to tell |
|---|---|---|
| You pressed Ctrl-Z instead of Ctrl-C | The server is paused, not stopped. It keeps the port but answers nothing, so the browser spins forever | STAT starts with T in ps; jobs in that terminal lists it |
| npm, a script runner or the editor was force-quit | Its child (the real server) is adopted by the system and keeps running | PPID is 1 |
| The terminal closed while the server ignored the hang-up signal | The server runs on, with no window | Its terminal is gone in ps -o tty |
A tool started it in the background (&, concurrently, an AI agent) | It runs until something stops it | etime is long; the folder is a project you finished with |
A paused server is the confusing one: lsof shows it listening, but requests just hang. Resume and stop it in the terminal where you pressed Ctrl-Z with fg, then Ctrl-C, or from anywhere with kill -CONT <PID>; kill <PID>.
Stop it from happening
- Stop servers with Ctrl-C before closing the tab. Ctrl-Z pauses; it doesn’t stop.
- Make Vite fail instead of moving to a new port with
--strictPort, so a leftover is obvious instead of silently running beside the new one. - Check before you start:
lsof -nP -iTCP:3000 -sTCP:LISTEN.
The one-click way: Portlivo
Portlivo lists every node, Vite, Next.js and Bun server in the menu bar by project name, with its port and how long it’s been up, so the one you forgot stands out. Stop it with one click, or several with Stop Visible. A server whose project folder is gone gets its own Leftover section.
From Terminal, portlivo ports lists them and portlivo kill 3000 stops whatever holds a port.
Questions people ask
- Does closing the terminal stop npm run dev?
- Usually, because the terminal sends a hang-up signal. Not when the server ignores it, was started in the background, or a wrapper in between was force-killed. Check with
lsof -nP -iTCP -sTCP:LISTEN. - Why does my browser keep loading forever on localhost?
- Often a server paused with Ctrl-Z: it holds the port but can’t answer.
ps -o stat -p <PID>showsT. Resume it withkill -CONT <PID>or stop it withkill <PID>. - Is killall node safe?
- It stops every Node process you own, including editor helpers and other projects. Stop the one PID you found instead.
Try Portlivo free for 7 days. Every feature, no account.Then $8.99 once, no subscription.
Download for MacSend to my MacStill have a question?
Write to us — a real developer reads every email and replies personally.