How to use nodemon to watch a folder being deleted and added back with new files?

Viewed 156

I have an app that generate build folder after building. Each time, the app will delete the whole build folder and add it back with new files inside.

I try to watch this folder change and do something.

nodemon --watch build --exec doSomething

However, this command will only watch if the build folder exists all the time and the file changes inside. It does not work when the whole folder got deleted and added back.

How to use nodemon to watch a folder got deleted and added back with new files with new files inside? Thanks

1 Answers

At least on MacOS, if the -L or --legacy-watch flags are used, nodemon stops working after the watched directory is deleted and fails to work correctly until the nodemon process is killed.

If the -L or --legacy-watch flags are omitted, nodemon works correctly after the watched directory is recreated.

Related