Is it possible to run a script on change using nodemon?
Is it possible to do something like this: nodemon --watch src --exec yarn run my-script
?
So, ideally I'd like to run a script only when there're changes in a src
folder
In your package. json file, create a start script. This will serve as the command that will be run and restarted by nodemon when a file changes. This passes the start script as the executable command to run for your project by nodemon.
Restart the application automatically The node command has to be re-executed in bash whenever there is a change in the application. To restart the application automatically, use the nodemon module. This local installation of nodemon can be run by calling it from within npm script such as npm start or using npx nodemon.
Just put quotes around your script that you want to execute:
nodemon --watch src --exec "yarn run my-script"
As indicated in the Nodemon docs you can add a restart event command in nodemon.json
:
{
"events": {
"restart": "yarn my-script"
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With