Use fs.watchFile instead of fs.watch for compatibility#7
Conversation
|
Thanks paton, this prompted me to read up on the two APIs a bit more: It looks like The only change I would prefer is to not poll every 150ms. Something like 500ms or 1s would seem adequate. |
|
500 / 1000ms isn't quite adequate in my case, as I often edit a file and refresh the page in less than that amount of time. Perhaps we can default it at 500ms and add an option to input a custom interval in the configuration. |
|
That sounds great -- would you mind updating the PR with a new option? |
|
Awesome! Will update the PR later today. |
|
@nicjansma just updated the PR. Let me know what you think |
Some text editors (like vim) write to a temp file, and the overwrite the original file with the temp file.
fs.watch works by listening to a particular file, so when I save a file, the original watcher is disconnected (because the file was overwritten by temp file) and the file is no longer being watched.
Switching to fs.watchFile fixes this problem because fs.watchFile works by polling the file to check for changes, while fs.watch uses a lower level file-watching feature of the operating system it's running on.
I've been using a version of this module with this change for the last year and it's worked well.