From 0e4f4266a1faacddc95fca8883d65646a2823c09 Mon Sep 17 00:00:00 2001 From: punteek Date: Fri, 16 Feb 2018 00:44:04 -0800 Subject: [PATCH] doc: add simple example to rename function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added a simple example showing how to rename a file. Refs: https://github.com/nodejs/node/issues11135 PR-URL: https://github.com/nodejs/node/pull/18812 Reviewed-By: Matheus Marchini Reviewed-By: Tiancheng "Timothy" Gu Reviewed-By: Tobias Nießen Reviewed-By: Gibson Fahnestock Reviewed-By: James M Snell --- doc/api/fs.md | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/doc/api/fs.md b/doc/api/fs.md index 34320bcf1fdafa..f59d58c7466a02 100644 --- a/doc/api/fs.md +++ b/doc/api/fs.md @@ -2529,8 +2529,19 @@ changes: * `callback` {Function} * `err` {Error} -Asynchronous rename(2). No arguments other than a possible exception are given -to the completion callback. +Asynchronously rename file at `oldPath` to the pathname provided +as `newPath`. In the case that `newPath` already exists, it will +be overwritten. No arguments other than a possible exception are +given to the completion callback. + +See also: rename(2). + +```js +fs.rename('oldFile.txt', 'newFile.txt', (err) => { + if (err) throw err; + console.log('Rename complete!'); +}); +``` ## fs.renameSync(oldPath, newPath)