From e9f96d8778320a1777d4dd6c2bbe2d1364ed0397 Mon Sep 17 00:00:00 2001 From: dustinnewman98 Date: Sat, 17 Feb 2018 16:09:05 -0800 Subject: [PATCH] doc: improved documentation for fs.unlink() Refs: https://github.com/nodejs/node/issues/11135 PR-URL: https://github.com/nodejs/node/pull/18843 Reviewed-By: Tiancheng "Timothy" Gu Reviewed-By: Benjamin Gruenbaum Reviewed-By: Ruben Bridgewater Reviewed-By: Sakthipriyan Vairamani Reviewed-By: Luigi Pinca Reviewed-By: Matheus Marchini --- doc/api/fs.md | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/doc/api/fs.md b/doc/api/fs.md index 510a44b9f2de2c..3fbdfc34726fe6 100644 --- a/doc/api/fs.md +++ b/doc/api/fs.md @@ -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)