how to read one line of a txt file at a time in node terminal code example

Example 1: node.js read text file line by line

const readline = require('readline');

const readInterface = readline.createInterface({
        input: fs.createReadStream('name.txt'),
        output: process.stdout,
        console: false
    });

 for await (const line of readInterface) {
        console.log(line);
    }
//or
readInterface.on('line', function(line) {
    console.log(line);
});

Example 2: how to get a particular line from a file in nodejs

lineReader.eachLine('path/to/file', function(line) {
    console.log(line);
    if (line.includes('STOP') {
        return false; // stop reading
    }
});