Skip to content

Commit e2190ad

Browse files
punteekMylesBorins
authored andcommitted
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: #22380 PR-URL: #18812 Reviewed-By: Matheus Marchini <[email protected]> Reviewed-By: Tiancheng "Timothy" Gu <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Gibson Fahnestock <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent d9895c4 commit e2190ad

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

doc/api/fs.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2238,8 +2238,19 @@ changes:
22382238
* `callback` {Function}
22392239
* `err` {Error}
22402240

2241-
Asynchronous rename(2). No arguments other than a possible exception are given
2242-
to the completion callback.
2241+
Asynchronously rename file at `oldPath` to the pathname provided
2242+
as `newPath`. In the case that `newPath` already exists, it will
2243+
be overwritten. No arguments other than a possible exception are
2244+
given to the completion callback.
2245+
2246+
See also: rename(2).
2247+
2248+
```js
2249+
fs.rename('oldFile.txt', 'newFile.txt', (err) => {
2250+
if (err) throw err;
2251+
console.log('Rename complete!');
2252+
});
2253+
```
22432254

22442255
## fs.renameSync(oldPath, newPath)
22452256
<!-- YAML

0 commit comments

Comments
 (0)