Node fs.promises.watch function | API Reference | Bun
BuildDocsReferenceGuidesBlogDiscord/
node:fs/promises/
watchFwatch
Search the reference...
/
BuildDocsReferenceGuidesBlogDiscord/
node:fs/promises/
watchFwatch
function
fs.promises.watch ac.abort(), 10000);
(async () => {
try {
const watcher = watch(__filename, { signal });
for await (const event of watcher)
console.log(event);
} catch (err) {
if (err.name === 'AbortError')
return;
throw err;
}
})();
```
On most platforms, `'rename'` is emitted whenever a filename appears or
disappears in the directory.
All the `caveats` for `fs.watch()` also apply to `fsPromises.watch()`." data-algolia-static="false" data-algolia-merged="false" data-type="Function">function
watch(filename:
PathLike,options?: BufferEncoding |
WatchOptionsWithStringEncoding): AsyncIterator
FileChangeInfostring>>;
Returns an async iterator that watches for changes on filename, where filenameis either a file or a directory.
import { watch } from 'node:fs/promises';
const ac = new AbortController();
const { signal } = ac;
setTimeout(() => ac.abort(), 10000);
(async () => {
try {
const watcher = watch(__filename, { signal });
for await (const event of watcher)
console.log(event);
} catch (err) {
if (err.name === 'AbortError')
return;
throw err;
}
})();
On most platforms, 'rename' is emitted whenever a filename appears or disappears in the directory.
All the caveats for fs.watch() also apply to fsPromises.watch().
@returns
of objects with the properties:
function
watch(filename:
PathLike,options: 'buffer' |
WatchOptionsWithBufferEncoding): AsyncIterator
FileChangeInfoNonSharedBuffer>>;
Returns an async iterator that watches for changes on filename, where filenameis either a file or a directory.
import { watch } from 'node:fs/promises';
const ac = new AbortController();
const { signal } = ac;
setTimeout(() => ac.abort(), 10000);
(async () => {
try {
const watcher = watch(__filename, { signal });
for await (const event of watcher)
console.log(event);
} catch (err) {
if (err.name === 'AbortError')
return;
throw err;
}
})();
On most platforms, 'rename' is emitted whenever a filename appears or disappears in the directory.
All the caveats for fs.watch() also apply to fsPromises.watch().
@returns
of objects with the properties:
function
watch(filename:
PathLike,options: BufferEncoding | 'buffer' |
WatchOptions): AsyncIterator
FileChangeInfostring | NonSharedBuffer>>;
Returns an async iterator that watches for changes on filename, where filenameis either a file or a directory.
import { watch } from 'node:fs/promises';
const ac = new AbortController();
const { signal } = ac;
setTimeout(() => ac.abort(), 10000);
(async () => {
try {
const watcher = watch(__filename, { signal });
for await (const event of watcher)
console.log(event);
} catch (err) {
if (err.name === 'AbortError')
return;
throw err;
}
})();
On most platforms, 'rename' is emitted whenever a filename appears or disappears in the directory.
All the caveats for fs.watch() also apply to fsPromises.watch().
@returns
of objects with the properties:
Referenced typestype
PathLike = string |
Buffer |
URLValid types for path values in "fs".
interface
WatchOptionsWithStringEncodingencoding?: BufferEncoding
ignore?:
WatchIgnorePredicate | readonly
WatchIgnorePredicate[]
maxQueue?: number
overflow?: 'ignore' | 'throw'
persistent?: boolean
recursive?: boolean
signal?:
AbortSignalinterface
FileChangeInfoT extends string |
Buffer>
eventType:
WatchEventTypefilename: null | Tinterface
WatchOptionsWithBufferEncodingencoding: 'buffer'
ignore?:
WatchIgnorePredicate | readonly
WatchIgnorePredicate[]
maxQueue?: number
overflow?: 'ignore' | 'throw'
persistent?: boolean
recursive?: boolean
signal?:
AbortSignalinterface
WatchOptionsencoding?: BufferEncoding | 'buffer'
ignore?:
WatchIgnorePredicate | readonly
WatchIgnorePredicate[]
maxQueue?: number
overflow?: 'ignore' | 'throw'
persistent?: boolean
recursive?: boolean
signal?:
AbortSignalResources
ReferenceDocsGuidesDiscordMerch StoreGitHubBlog Toolkit
RuntimePackage managerTest runnerBundlerPackage runnerProject
Bun 1.0Bun 1.1Bun 1.2Bun 1.3RoadmapContributingLicenseBaked with ❤️ in San Francisco
We're hiring →