doc: add simple example to rename function

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 <matheus@sthima.com>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
punteek authored and Myles Borins committed 2018-09-06 09:40:50 -07:00
1 parent d9895c4ba7
commit e2190ad755
1 file changed
+13 -2
+13 -2
View File
@@ -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)
<!-- YAML