Beginner
Beginner

Reputation: 9095

Is there a difference between `npm start` and `npm run start`?

I am able to run both the npm start and npm run start commands. I used create-react-app to create my application. To make configuration changes in the CSS module, I want to run npm eject but it throws an error.

The npm run eject command works however. I'm confused as to why npm eject did not work. Can I configure it to work?

Below is my package.json file:

"scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject"
}

Upvotes: 270

Views: 192404

Answers (5)

halilenesozdemir
halilenesozdemir

Reputation: 1

Some commands are recognized by npm by default to simplify certain tasks. Just like "npm start,npm test,npm stop,npm restart", as noted by @AKX.

These commands are directly recognized by npm, that's why we don't need to use the npm run prefix.

However, for other commands like build, we need to use npm run build, because build is not directly recognized by npm and is considered a user-defined script.

If you want to examine this topic: https://docs.npmjs.com/cli/v7/using-npm/scripts

Upvotes: 0

Kasun Wimaladarma
Kasun Wimaladarma

Reputation: 187

Telling this because sometimes this can be help to someone. Inside the jenkins pipelines you should use npm commands with "run" ex- npm run start if not the command will not be executed.

Upvotes: 5

Vimal Maheedharan
Vimal Maheedharan

Reputation: 755

One interesting thing to note is,
If the scripts object does not have a "start" property in package.json file, npm start or npm run start from command line will run node server.js by default.

But if the scripts object in package.json has "start" property, it overrides node server.js and executes the command in "start" property.

See - https://docs.npmjs.com/cli/v7/commands/npm-start#description

Upvotes: 21

Ayushi Jain
Ayushi Jain

Reputation: 928

npm start is the short form for npm run start. So, its one and the same thing.

Upvotes: 40

AKX
AKX

Reputation: 168967

npm test, npm start, npm restart, and npm stop are all aliases for npm run xxx.

For all other scripts you define, you need to use the npm run xxx syntax.

See the docs at https://docs.npmjs.com/cli/run-script for more information.

Upvotes: 481

Related Questions