Automate Tasks With npm Scripts

npm·1 min read·Jan 1, 2025

In npm, scripts are a set of built-in and custom commands used to automate the execution of repetitive project-related tasks, such as starting the web server, bundling the application, linting the code, running automated tests, and so on.

Define and execute scripts

Define a script

Scripts are defined under the scripts property of the package.json file using the following syntax:

{  "scripts": {    "<name>": "<command>"  }}

Where:

  • <name> is the name of the script (e.g. build, lint).
  • <command> is the shell command to be executed when invoking the script.

Execute a script

To run an arbitrary script, you can use the npm run command:

$ npm run <script>

Unlock the program 🚀

Pay once, own it forever.

€79

30-day money-back guarantee

  • 13 modules
  • 113 lessons with full-code examples
  • 29 projects with commented solutions
  • All future lesson and project updates
  • Lifetime access

By submitting this form, you agree to the Terms & Conditions and Privacy Policy.