The package.json file allows us to specify a “prestart” script.
When does the npm prestart script run?
The entry under “prestart” will run first when “start” is called, before the script specified by “start“.
The example below demonstrates this.
package.json:
{ "name": "example-repo", "scripts": { "prestart": "echo 'In prestart...'", "start": "node index.js" } }
Running start:
$ npm run start
Output:
> prestart > echo 'In prestart...' In prestart... > start > node index.js
This can be useful to run scripts required as a pre-requisite for running a build, for example.