How to run start scripts from package.json?
Asked Answered
T

3

16

I've two scripts in package.json

"start:dev": "nodemon ./src/index.js",
"start": "npm run build && node ./build/index.js",

npm start works well. I need to run "start:dev": "nodemon ./src/index.js"

Tortricid answered 18/2, 2017 at 7:40 Comment(0)
C
19

For most custom npm scripts you need to add run before script name npm run start:dev

Conquest answered 18/2, 2017 at 7:45 Comment(0)
R
16

npm - The main scripts such as start, stop, restart, install, version or test do not require run command. These scripts and some other are described in npm documentation.

npm start

The others need run command before the script name as was pointed by David.

npm run start:dev

Yarn - You can also use yarn and in that case you do not have to specify run.

yarn start

yarn start:dev
Roos answered 19/8, 2017 at 14:22 Comment(2)
Great, but when we need to put a colon in between? like start:devTortricid
You do not have to put a colon between words. It is just for readability. You can completely omit it or use dash or underscore instead if you want.Roos
F
1

Update as of 2024

If you are using Node.js 22 or higher, you don't need to use npm run. Node.js provides a faster and native alternative.

The node --run command will execute the scripts in package.json:

node --run start

Or like this:

node --run start:dev
Flowerer answered 25/4 at 15:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.