![]() |
VOOZH | about |
The fs.unlinkSync() method is used to synchronously remove a file or symbolic link from the filesystem. This function does not work on directories, therefore it is recommended to use fs.rmdir() to remove a directory.
Syntax:
fs.unlinkSync( path )
Parameters: This method accepts one parameter as mentioned above and described below:
Below examples illustrate the fs.unlinkSync() method in Node.js:
Example 1: This example removes a file from the filesystem.
Output:
Files present in directory:
index.html
index.js
package.json
readme.md
File readme.md is deleted
Files present in directory:
index.html
index.js
package.json
Example 2: This example removes a symbolic link from the filesystem.
Output:
Symbolic link to readme.md created
Files present in directory:
index.html
index.js
package.json
readme.md
symlinkToReadme
Symbolic link to readme.md deleted
Files present in directory:
index.html
index.js
package.json
readme.md
Reference:https://nodejs.org/api/fs.html#fs_fs_unlinksync_path