Automating Common Tasks With npm Scripts
npm·2 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.
Defining and executing scripts
Defining 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.
Unlock the Build CLI Apps in JavaScript & Node.js module
Learn how to build, integrate, and safeguard scalable CLI tools, scripts, and apps with JavaScript, Node.js, npm, and Git.
You get immediate access to:
- 45 focused lessons across JavaScript, Node.js, npm, and Git
- 17 real-world projects with commented solutions
- Ongoing updates to this bundle
- Lifetime access to this bundle