diff options
author | Juan José Arboleda <soyjuanarbol@gmail.com> | 2021-07-20 00:22:24 +0300 |
---|---|---|
committer | James M Snell <jasnell@gmail.com> | 2021-07-28 23:36:45 +0300 |
commit | 7f167f49dddb48fb29d4b5e5a5aa126163af4e76 (patch) | |
tree | 0cd34629c065722469b6190d3591043f9220f6bb /doc/api | |
parent | 984f7a0bf32f9e329d0b7975042f71212fa823c4 (diff) |
doc: add code example to `fs.truncate` method
PR-URL: https://github.com/nodejs/node/pull/39454
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'doc/api')
-rw-r--r-- | doc/api/fs.md | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/doc/api/fs.md b/doc/api/fs.md index 72170f13193..f17f0559753 100644 --- a/doc/api/fs.md +++ b/doc/api/fs.md @@ -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. |