文件名参数
仅在 Linux、macOS、Windows 和 AIX 上支持在回调中提供 filename
参数。
即使在支持的平台上,也不能保证始终提供 filename
。
因此,不要假设回调中总是提供 filename
参数,如果它为 null
,则有一些回退逻辑。
import { watch } from 'node:fs';
watch('somedir', (eventType, filename) => {
console.log(`event type is: ${eventType}`);
if (filename) {
console.log(`filename provided: ${filename}`);
} else {
console.log('filename not provided');
}
});
Providing filename
argument in the callback is only supported on Linux,
macOS, Windows, and AIX. Even on supported platforms, filename
is not always
guaranteed to be provided. Therefore, don't assume that filename
argument is
always provided in the callback, and have some fallback logic if it is null
.
import { watch } from 'node:fs';
watch('somedir', (eventType, filename) => {
console.log(`event type is: ${eventType}`);
if (filename) {
console.log(`filename provided: ${filename}`);
} else {
console.log('filename not provided');
}
});