Nodemon execute different scripts based on the changed file name
Asked Answered
E

1

9

I am trying to make Nodemon run two different commands depending on which file changed. I tried using nodemon.json and invoking it using nodemon nodemon.json (because it didn't seem to be getting picked up just by nodemon):

{
  "watch": "nodemon.json,main.js,index.js",
  "execMap": {
    "main.js": "electron .",
    "index.js": "echo todo",
    "nodemon.json": "echo Nodemon config reloaded"
  }
}

Nodemon doesn't pick up any changes with this setup. I think I might have a problem in the watch glob. When I remove it (so it watches everything I think by default), then file changes are getting picked up, but Nodemon only ever executes node index.js. I never speficied that anywhere so I assume that's the default and the execMap is not being honored? Is it only for extensions?

I am not sure how to craft a config which takes these two different paths. Is it even possible with Nodemon?

Everything answered 15/8, 2019 at 15:1 Comment(0)
F
0

The execMap property seems to be intended to support non-default file extensions.

According to the docs

...you can define your own default executables using the execMap property. This is particularly useful if you're working with a language that isn't supported by default by nodemon

One thing you can do is run multiple nodemon processes, one for each file/directory, from a script, like:

nodemon -w "path1/" -x "<command 1>" &
nodemon -w "path2/" -x "<command 2>"
Fundamentalism answered 29/1, 2022 at 14:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.