What does npm run dev do?
By Flavio Copes
Learn what npm run dev does, why it keeps running, how to stop it with Ctrl-C, and how to pass a custom port or host to the development server.
npm run dev runs the command stored in the dev script of your project’s package.json file.
It usually starts a development server. The command keeps running because that server must stay available while you work.
What command does npm run dev run?
Look at the scripts field in package.json:
{
"scripts": {
"dev": "astro dev"
}
}
With this configuration, npm run dev runs astro dev.
dev is not a special built-in npm command. A project can define it using Astro, Next.js, Vite, Node, or any other program.
You can run npm run without a script name to list the scripts available in the current project. My npm guide explains how project scripts work.
How do you stop npm run dev?
Return to the terminal where the server is running and press Ctrl-C.
That sends an interrupt signal to the process. The server should stop and return control to the terminal.
If you close the terminal or start the command again elsewhere, the first process may still own its port. This is why a second server sometimes starts on port 3001 instead of 3000.

How do you run the development server on a specific port?
Arguments after -- are passed to the command in the npm script:
npm run dev -- --port 3000
This works when the underlying development server supports a --port option. Check that tool’s documentation because the available arguments belong to Astro, Next.js, Vite, or whichever program the script runs.
The same rule applies to options such as --host:
npm run dev -- --host
If port 3000 is already occupied, stop the other development server first. Then run the command again.
Related posts about node: