diff --git a/doc/api/fs.md b/doc/api/fs.md index b9d1f018450b6d..3e5ff52986163a 100644 --- a/doc/api/fs.md +++ b/doc/api/fs.md @@ -515,6 +515,46 @@ If one or more `filehandle.read()` calls are made on a file handle and then a position till the end of the file. It doesn't always read from the beginning of the file. +#### `filehandle.readLines([options])` + + + +* `options` {Object} + * `encoding` {string} **Default:** `null` + * `autoClose` {boolean} **Default:** `true` + * `emitClose` {boolean} **Default:** `true` + * `start` {integer} + * `end` {integer} **Default:** `Infinity` + * `highWaterMark` {integer} **Default:** `64 * 1024` +* Returns: {readline.InterfaceConstructor} + +Convenience method to create a `readline` interface and stream over the file. +See [`filehandle.createReadStream()`][] for the options. + +```mjs +import { open } from 'node:fs/promises'; + +const file = await open('./some/file/to/read'); + +for await (const line of file.readLines()) { + console.log(line); +} +``` + +```cjs +const { open } = require('node:fs/promises'); + +(async () => { + const file = await open('./some/file/to/read'); + + for await (const line of file.readLines()) { + console.log(line); + } +})(); +``` + #### `filehandle.readv(buffers[, position])`