npm Scripts
npm scripts are short commands saved in package.json. One short name runs a longer command.
The scripts section
This part of package.json holds two scripts. Each one runs a file named greet.js.
"scripts": {
"greet": "node greet.js",
"start": "node greet.js"
}Run the start script
This command runs the start script. The output is the greeting from greet.js.
npm startExample
npm run greetKey points
- Scripts live in the scripts part of package.json.
- Each script has a short name and a command.
- Run npm run greet to run the script named greet.
- npm start is the short form for npm run start.
- The start script usually starts the project.
- Scripts keep long commands short and easy to remember.
In this example, npm run greet runs the script named greet. The middle lines echo the script name and its command. The last line is the greeting printed by greet.js.
Note
Run npm commands from inside the project folder.
Try it Yourself
Edit the code, then press Run.
Running is simulated
Exercise
How do you run the script named greet?