What is the difference between npm run serve
and npm run dev
in vuejs. Why should i use npm run serve command to run the project
npm run serve is basically asking the package manager (npm) to run the command specified under the name serve in the package. json file. The same goes for the npm run dev command. It is possible that both execute the same command or different things.
The npm run dev command is a generic npm command that you can find in many modern web application projects. This command is used to run the dev script defined in the project's package. json file.
serve is a NPM package that converts our current working directory into an virtual directory i.e. the directory is hosted under localhost.
npm run sets the NODE environment variable to the node executable with which npm is executed. If you try to run a script without having a node_modules directory and it fails, you will be given a warning to run npm install , just in case you've forgotten.
npm run serve
basically is just saying "npm please run the command I defined under the name serve in package.json" the same happens with npm run dev
.
Given this the commands can do the exact same thing, similar things, or very different things. Usually they are a shorthand for running a dev server on localhost, but it’s not a rule, only a convention.
So you'll need to check in your package.json
file and look for
"scripts": { "serve": "[list of commands here]", "dev": "[list of commands here]" },
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With