16

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

Le garcon
  • 7,197
  • 9
  • 31
  • 46

2 Answers2

34

Just put quotes around your script that you want to execute:

nodemon --watch src --exec "yarn run my-script"
KyleMit
  • 30,350
  • 66
  • 462
  • 664
user1627270
  • 491
  • 1
  • 4
  • 2
15

As indicated in the Nodemon docs you can add a restart event command in nodemon.json:

{
  "events": {
    "restart": "yarn my-script"
  }
}
Alan Friedman
  • 1,582
  • 9
  • 7