From 6e934b79a96397ff66fa879ac69dcc8bba445c72 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 Added a simple example showing how to rename a file. Refs: https://github.com/nodejs/node/issues11135 --- 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 2210d7ecb3b96f..147d188ce4aae4 100644 --- a/doc/api/fs.md +++ b/doc/api/fs.md @@ -2526,8 +2526,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)