Skip to content

Commit

Permalink
doc: improved documentation for fs.unlink()
Browse files Browse the repository at this point in the history
Refs: #11135

PR-URL: #18843
Reviewed-By: Tiancheng "Timothy" Gu <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Sakthipriyan Vairamani <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Matheus Marchini <[email protected]>
  • Loading branch information
dustinnewman authored and MylesBorins committed Aug 16, 2018
1 parent 8c5ad68 commit a1902ca
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions doc/api/fs.md
Original file line number Diff line number Diff line change
Expand Up @@ -2444,8 +2444,21 @@ changes:
* `callback` {Function}
* `err` {Error}

Asynchronous unlink(2). No arguments other than a possible exception are given
to the completion callback.
Asynchronously removes a file or symbolic link. No arguments other than a
possible exception are given to the completion callback.

```js
// Assuming that 'path/file.txt' is a regular file.
fs.unlink('path/file.txt', (err) => {
if (err) throw err;
console.log('path/file.txt was deleted');
});
```

`fs.unlink()` will not work on a directory, empty or otherwise. To remove a
directory, use [`fs.rmdir()`][].

See also: unlink(2)

## fs.unlinkSync(path)
<!-- YAML
Expand Down Expand Up @@ -3173,6 +3186,7 @@ The following constants are meant for use with the [`fs.Stats`][] object's
[`fs.read()`]: #fs_fs_read_fd_buffer_offset_length_position_callback
[`fs.readFile()`]: #fs_fs_readfile_path_options_callback
[`fs.readFileSync()`]: #fs_fs_readfilesync_path_options
[`fs.rmdir()`]: #fs_fs_rmdir_path_callback
[`fs.stat()`]: #fs_fs_stat_path_callback
[`fs.utimes()`]: #fs_fs_utimes_path_atime_mtime_callback
[`fs.watch()`]: #fs_fs_watch_filename_options_listener
Expand Down

0 comments on commit a1902ca

Please sign in to comment.