Skip to content

Commit 2129ad6

Browse files
juanarboldanielleadams
authored andcommitted
doc: add code example to fs.truncate method
PR-URL: #39454 Reviewed-By: James M Snell <[email protected]>
1 parent 3ff5e15 commit 2129ad6

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

doc/api/fs.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3452,6 +3452,24 @@ Truncates the file. No arguments other than a possible exception are
34523452
given to the completion callback. A file descriptor can also be passed as the
34533453
first argument. In this case, `fs.ftruncate()` is called.
34543454

3455+
```mjs
3456+
import { truncate } from 'fs';
3457+
// Assuming that 'path/file.txt' is a regular file.
3458+
truncate('path/file.txt', (err) => {
3459+
if (err) throw err;
3460+
console.log('path/file.txt was truncated');
3461+
});
3462+
```
3463+
3464+
```cjs
3465+
const { truncate } = require('fs');
3466+
// Assuming that 'path/file.txt' is a regular file.
3467+
truncate('path/file.txt', (err) => {
3468+
if (err) throw err;
3469+
console.log('path/file.txt was truncated');
3470+
});
3471+
```
3472+
34553473
Passing a file descriptor is deprecated and may result in an error being thrown
34563474
in the future.
34573475

0 commit comments

Comments
 (0)