You can define scripts that can be executed or are triggered before or after another script.
{
  "scripts": {
    "pretest": "scripts/pretest.js",
    "test": "scripts/test.js",
    "posttest": "scripts/posttest.js"
  }
}
In this case, you can execute the script by running either of these commands:
$ npm run-script test
$ npm run test
$ npm test
$ npm t
| Script Name | Description | 
|---|---|
| prepublish | Run before the package is published. | 
| publish, postpublish | Run after the package is published. | 
| preinstall | Run before the package is installed. | 
| install, postinstall | Run after the package is installed. | 
| preuninstall, uninstall | Run before the package is uninstalled. | 
| postuninstall | Run after the package is uninstalled. | 
| preversion, version | Run before bump the package version. | 
| postversion | Run after bump the package version. | 
| pretest, test, posttest | Run by the npm testcommand | 
| prestop, stop, poststop | Run by the npm stopcommand | 
| prestart, start, poststart | Run by the npm startcommand | 
| prerestart, restart, postrestart | Run by the npm restartcommand | 
You can also define your own scripts the same way you do with the pre-defined scripts:
{
  "scripts": {
    "preci": "scripts/preci.js",
    "ci": "scripts/ci.js",
    "postci": "scripts/postci.js"
  }
}
In this case, you can execute the script by running either of these commands:
$ npm run-script ci
$ npm run ci
User-defined scripts also supports pre and post scripts, as shown in the example above.