Skip to content

Replacements for split

readline.createInterface (native, since Node.js v6.6.0)

The readline.createInterface method can be used to read a stream line by line, effectively replacing the functionality of the split package.

Example:

js
import split from 'split'
import { createInterface } from 'node:readline'
import * as fs from 'node:fs'

const input = fs.createReadStream('file.txt')

const stream = input.pipe(split()) 
stream.on('data', (line) => { 
  fn(line) 
}) 

const lines = createInterface({ input, crlfDelay: Infinity }) 

for await (const line of lines) { 
  fn(line) 
} 

Released under the MIT License. (ca40e9e1)