Running npm run dev starts a development server so you can preview an application while you work. When you are finished, switching projects, or need to restart the server, you may wonder how to stop it cleanly. In most cases, you can close it with a keyboard shortcut in the terminal where it is running. If that does not work, you can stop the related process or free the port it is using. This guide explains how to close npm run dev on macOS, Windows, and Linux, and what to try when the server keeps running.
The Quickest Way to Close npm run dev
Go to the terminal window or terminal tab where you started the development server. Click inside it to make sure it is active, then press Ctrl + C. On macOS, Windows, and most Linux terminals, this sends an interrupt signal to the running command. You will usually see a message such as ^C, and the terminal prompt will return.
For example, if you started the server with:
npm run dev
press Ctrl + C in that same terminal. You do not usually need to type a separate npm command to shut it down. The shortcut interrupts the script and its development server, allowing you to enter another command or close the terminal.
-
Windows: Press
Ctrl + Cin Command Prompt, PowerShell, or the VS Code terminal. -
macOS: Press
Control + Cin Terminal, iTerm, or your editor’s terminal. -
Linux: Press
Ctrl + Cin your terminal emulator.
Be sure to use the Control key, not the Command key on a Mac. If the shortcut seems to do nothing, click the terminal first and try it again. The browser page displaying your app is not the place to enter the shortcut; it must be sent to the terminal process.
What Ctrl + C Does
npm run dev runs the dev script listed in your project’s package.json file. That script commonly starts a tool such as Vite, Next.js, Astro, or a framework-specific development server. The server keeps running so it can respond to browser requests and monitor your files for changes.
Pressing Ctrl + C sends an interrupt to the foreground process in the terminal. In a typical setup, npm passes that interrupt along to the development server, which shuts down and releases the port it was using. The browser may then show an error if you refresh the page, because the local server is no longer available. That is expected: closing the server does not delete your project or its files.
If the terminal asks whether you want to terminate a batch job, confirm the prompt when you intend to stop the server. The exact wording depends on your operating system and terminal. Once the prompt returns, the development process has generally ended.
How to Stop the Server in VS Code
If you started npm run dev in Visual Studio Code, use the integrated terminal where the command is running. Select that terminal, then press Ctrl + C on Windows or Linux, or Control + C on macOS.
You can also use the terminal panel’s trash-can icon to terminate the active terminal session. This closes the shell and usually stops its foreground process. However, using Ctrl + C first is a clearer way to interrupt the server gracefully. Avoid closing a different terminal tab by mistake if you have several commands running.
Some editors offer a stop button for a task or debug session. Use that button if you launched the server through the editor’s task runner or debugger rather than by typing the command directly. The key idea is to stop the process from the same tool or session that started it.
How to Close npm run dev in a Separate Terminal
If the terminal that started the server is still open, return to it and press Ctrl + C. If you closed the window, started the process in the background, or cannot find its session, you may need to locate and stop the process that is listening on the development server’s port.
First, check the startup message in your terminal or browser address bar. Many development servers use port 3000, 5173, or another port, but the actual value depends on the project. Do not assume the server is using a particular port without checking. You can then identify the process using the appropriate command for your operating system.
Stop a Development Server on macOS or Linux
On macOS or Linux, the lsof command can show which process is using a port. Replace 5173 below with the port your server actually uses:
lsof -i :5173
Look for the process ID, often shown under the PID column. Before stopping it, confirm that it is the development server you intend to close. Then send it a normal termination signal by replacing 12345 with the displayed process ID:
kill 12345
A normal kill gives a process an opportunity to exit cleanly. If it does not stop and you have confirmed that the process is safe to terminate, you can use a forceful signal as a last resort:
kill -9 12345
Use kill -9 cautiously. It ends a process immediately rather than allowing it to perform cleanup. Also, do not copy a sample process ID literally; process IDs change each time programs run.
Stop a Development Server on Windows
On Windows, open PowerShell or Command Prompt and find the process using the server’s port. In this example, the port is 3000:
netstat -ano | findstr :3000
The output includes a process ID in the final column. Confirm that the listed connection is associated with the port you want to free, then stop that specific process from PowerShell or Command Prompt:
taskkill /PID 12345 /F
Replace 12345 with the actual process ID. The /F option forces termination, so use it only after you have checked that you are stopping the correct process. If you are unsure, return to the original terminal and try Ctrl + C before using a forceful command.
Windows Terminal, PowerShell, and Command Prompt may display slightly different output, but the general steps are the same: identify the process by port, verify its process ID, and stop only that process.
What to Do When Ctrl + C Does Not Work
If Ctrl + C does not appear to stop npm run dev, check a few common causes before ending processes manually:
- The terminal is not focused. Click inside the terminal that is running the command, then press the shortcut again.
- You are in the wrong terminal tab. Find the session that shows the server’s startup messages and send the interrupt there.
- The process is waiting for input. Read the latest terminal output. A prompt may require a response before the process can exit.
- The terminal is temporarily busy. Give it a moment, especially if the server is performing a task, then try the shortcut once more.
- The server was started elsewhere. Check another terminal window, editor task, or background session that may have launched the command.
On some Windows setups, Ctrl + C may display a confirmation asking whether to terminate a batch job. Answer as prompted if you want to stop it. If your keyboard or terminal does not send the interrupt correctly, you can try Ctrl + Break where the keyboard and terminal support it.
As a last resort, identify the process using its port and terminate it using the macOS, Linux, or Windows instructions above. Avoid ending every process named node. You may have other Node.js programs running, and stopping them all can interrupt unrelated projects or tools.
How to Fix “Port Is Already in Use”
A message that a port is already in use usually means another process is still listening on the port the development server wants. The original server may still be running in a different terminal, or another application may be using the same port. This message does not necessarily mean npm itself is broken.
Look through your open terminal tabs for a running development server. If you find it, stop it with Ctrl + C. If not, identify the process using the port with lsof on macOS or Linux, or netstat on Windows, as described above. Verify the process before stopping it.
Some development tools offer to switch to another port automatically. If you accept that option, the server may start at a different local address. That is a workaround, not a way to close the previous server. If you want to stop the old process, locate its terminal or process ID and end it directly.
Does Closing the Terminal Stop npm run dev?
Closing the terminal window often ends the shell and the development server it launched, but behavior can vary. Some terminal applications, editor tasks, background commands, or process managers may leave a process running after its original window closes. For predictable results, stop the server with Ctrl + C before closing the terminal.
If you started the command with a tool that keeps processes running in the background, use that tool’s stop command or interface. A process manager, container, remote development environment, or cloud workspace may have its own controls. Closing a local browser tab does not stop the server, because the browser is only connecting to it.
How to Restart the Development Server
To restart the server, first stop the running command with Ctrl + C and wait until the terminal prompt returns. Then run the development script again:
npm run dev
If the project uses a different package manager, use the command documented in its project files. For example, a project may provide instructions for Yarn or pnpm. The important point is to stop the active server before starting another copy if you do not want two development processes running at once.
If you are not sure what the project’s dev script does, open package.json and look under scripts. This can help you identify the framework and understand which command starts the local server. You generally do not need to edit the script just to stop it.
Frequently Asked Questions
Does Ctrl + C delete anything? No. It interrupts the running command. It does not remove project files, packages, or source code.
Can I stop the server by closing my browser? No. Closing the browser tab ends that browser view, but the development server continues running in the terminal until you stop its process.
Why does the website stop loading after I close the server? A local development server must be running to serve the app. After you interrupt it, the browser cannot reach the local address until you start the server again.
Is there an npm stop command? Not usually for a standard development script. Unless the project defines a separate stop script, use Ctrl + C in the terminal where npm run dev is running.
Conclusion
The simplest way to close npm run dev is to focus the terminal where it is running and press Ctrl + C. This works in most Windows, macOS, and Linux terminals and usually shuts down the development server cleanly. If you cannot access the original session, check which process is using the server’s port and stop only that process. Once the terminal prompt returns, the server is closed; run npm run dev again whenever you are ready to continue development.
Disclaimer: Articles are written by Humans, AI or Both. Verify Important information.