Skip to content

Commit

Permalink
doc: add code example to fs.truncate method
Browse files Browse the repository at this point in the history
PR-URL: #39454
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
juanarbol authored and jasnell committed Jul 28, 2021
1 parent 984f7a0 commit 7f167f4
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions doc/api/fs.md
Original file line number Diff line number Diff line change
Expand Up @@ -3502,6 +3502,24 @@ Truncates the file. No arguments other than a possible exception are
given to the completion callback. A file descriptor can also be passed as the
first argument. In this case, `fs.ftruncate()` is called.

```mjs
import { truncate } from 'fs';
// Assuming that 'path/file.txt' is a regular file.
truncate('path/file.txt', (err) => {
if (err) throw err;
console.log('path/file.txt was truncated');
});
```

```cjs
const { truncate } = require('fs');
// Assuming that 'path/file.txt' is a regular file.
truncate('path/file.txt', (err) => {
if (err) throw err;
console.log('path/file.txt was truncated');
});
```

Passing a file descriptor is deprecated and may result in an error being thrown
in the future.

Expand Down

0 comments on commit 7f167f4

Please sign in to comment.