Nodejs fs.watch (https://nodejs.org/api/fs.html#caveats) is implemented using kqueue (https://www.freebsd.org/cgi/man.cgi?query=kqueue&sektion=2) for FreeBSD.
Here is a small piece of code that uses fs.watch taken from the above nodejs page (slightly modified to watch a subdirectory ./src):
I save the above code in testwatch.mjs in the parent directory and run from a terminal:
and leave it running.
In another terminal, I first cd to src and then use vim to edit a file called test.txt and enter "this is a test" and save the file. I see the following in the first terminal:
Here is my question. Is there a way to get the filename that was modified?
Having the filename would allow webpack-dev-server to rebuild a Reactjs application (client-side JavaScript) created using create-react-app which would automatically rerender the changes on the browser using the HotModuleReplacement plugin when one is using the development mode in create-react-app. Webpack-dev-server uses fs.watch to watch for file modifications.
Here is a small piece of code that uses fs.watch taken from the above nodejs page (slightly modified to watch a subdirectory ./src):
Code:
import { watch } from 'node:fs';
watch('./src', (eventType, filename) => {
console.log(`event type is: ${eventType}`);
if (filename) {
console.log(`filename provided: ${filename}`);
} else {
console.log('filename not provided');
}
});
node testwatch.mjs
and leave it running.
In another terminal, I first cd to src and then use vim to edit a file called test.txt and enter "this is a test" and save the file. I see the following in the first terminal:
Code:
node testwatch.mjs
event type is: rename
filename not provided
event type is: rename
filename not provided
event type is: rename
filename not provided
^C
Here is my question. Is there a way to get the filename that was modified?
Having the filename would allow webpack-dev-server to rebuild a Reactjs application (client-side JavaScript) created using create-react-app which would automatically rerender the changes on the browser using the HotModuleReplacement plugin when one is using the development mode in create-react-app. Webpack-dev-server uses fs.watch to watch for file modifications.