From 0be2ac95170f260330dd3b1e61156e799978b384 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Jos=C3=A9=20Arboleda?= Date: Mon, 19 Jul 2021 16:22:24 -0500 Subject: [PATCH] doc: add code example to `fs.truncate` method --- doc/api/fs.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/doc/api/fs.md b/doc/api/fs.md index 72170f13193fe7..f17f05597533d8 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.