Skip to content

Commit 898db5a

Browse files
juanarboltargos
authored andcommitted
doc: add code example to fs.truncate method
PR-URL: #39454 Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 05d7460 commit 898db5a

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
@@ -3412,6 +3412,24 @@ Truncates the file. No arguments other than a possible exception are
34123412
given to the completion callback. A file descriptor can also be passed as the
34133413
first argument. In this case, `fs.ftruncate()` is called.
34143414

3415+
```mjs
3416+
import { truncate } from 'fs';
3417+
// Assuming that 'path/file.txt' is a regular file.
3418+
truncate('path/file.txt', (err) => {
3419+
if (err) throw err;
3420+
console.log('path/file.txt was truncated');
3421+
});
3422+
```
3423+
3424+
```cjs
3425+
const { truncate } = require('fs');
3426+
// Assuming that 'path/file.txt' is a regular file.
3427+
truncate('path/file.txt', (err) => {
3428+
if (err) throw err;
3429+
console.log('path/file.txt was truncated');
3430+
});
3431+
```
3432+
34153433
Passing a file descriptor is deprecated and may result in an error being thrown
34163434
in the future.
34173435

0 commit comments

Comments
 (0)