Skip to content

Commit 7f167f4

Browse files
juanarboljasnell
authored andcommitted
doc: add code example to fs.truncate method
PR-URL: #39454 Reviewed-By: James M Snell <[email protected]>
1 parent 984f7a0 commit 7f167f4

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

doc/api/fs.md

+18
Original file line numberDiff line numberDiff line change
@@ -3502,6 +3502,24 @@ Truncates the file. No arguments other than a possible exception are
35023502
given to the completion callback. A file descriptor can also be passed as the
35033503
first argument. In this case, `fs.ftruncate()` is called.
35043504

3505+
```mjs
3506+
import { truncate } from 'fs';
3507+
// Assuming that 'path/file.txt' is a regular file.
3508+
truncate('path/file.txt', (err) => {
3509+
if (err) throw err;
3510+
console.log('path/file.txt was truncated');
3511+
});
3512+
```
3513+
3514+
```cjs
3515+
const { truncate } = require('fs');
3516+
// Assuming that 'path/file.txt' is a regular file.
3517+
truncate('path/file.txt', (err) => {
3518+
if (err) throw err;
3519+
console.log('path/file.txt was truncated');
3520+
});
3521+
```
3522+
35053523
Passing a file descriptor is deprecated and may result in an error being thrown
35063524
in the future.
35073525

0 commit comments

Comments
 (0)