Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run start scripts from package.json?

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"

like image 500
Hashir Hussain Avatar asked Feb 18 '17 07:02

Hashir Hussain


People also ask

How do I run a script in package json?

json file: To execute your Script, use the 'npm run <NAME-OF-YOUR-SCRIPT>' command. Some predefined aliases convert to npm run, like npm test or npm start, you can use them interchangeably.

How do I run a script after npm install?

You can use npm hook scripts to do something after package is installed. Create node_modules/. hooks/postinstall executable and it will be run also after npm install <package> .

Where is the Run command defined in package json?

You can easily run scripts using npm by adding them to the "scripts" field in package. json and run them with npm run <script-name> . Run npm run to see available scripts. Binaries of locally install packages are made available in the PATH , so you can run them by name instead of pointing to node_modules/.


2 Answers

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

like image 134
David Diefenderfer Avatar answered Sep 22 '22 23:09

David Diefenderfer


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
like image 26
Black Avatar answered Sep 21 '22 23:09

Black