From e2190ad755be4d09bc0cd654e8382c08215c885b 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 Backport-PR-URL: https://github.com/nodejs/node/pull/22380 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 3fbdfc34726fe6..a50640477dcfa1 100644 --- a/doc/api/fs.md +++ b/doc/api/fs.md @@ -2238,8 +2238,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)