VOOZH about

URL: https://www.geeksforgeeks.org/node-js/node-js-fs-unwatchfile-method/

⇱ Node.js fs.unwatchFile() Method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Node.js fs.unwatchFile() Method

Last Updated : 8 Oct, 2021
The fs.unwatchFile() method is used to stop watching for changes on the given file. An optional listener parameter can be specified to remove only the specified listener from the file. Otherwise, all the listeners associated with the file are removed. If the file is not being watched when this function is used, then it does not perform any operation and throw any error. Syntax:
fs.unwatchFile(filename[, listener])
Parameters: This method accepts two parameters as mentioned above and described below:
  • filename: It is a String, Buffer or URL that denotes the file that has to be stopped from watching.
  • listener: It is a function that specifies the listener previously attached using the fs.watchFile() function. If specified, only this particular listener is removed. It is an optional parameter.
Below examples illustrate the fs.unwatchFile() method in Node.js. Example 1: Output:
The file was edited
Previous Modified Time: 2020-05-30T08:43:28.216Z
Current Modified Time: 2020-05-30T08:43:37.208Z

File has been stopped watching
Example 2: Output:
Listener 1: File Modified
Listener 2: File Modified

Listener 1 has been stopped!

Listener 2: File Modified
Reference: https://nodejs.org/api/fs.html#fs_fs_unwatchfile_filename_listener
Comment

Explore