Read text file stream line by line passed through Nodejs request
$ npm install text-readline
$ yarn add text-readline
const textReadline = require('text-readline');
...
const middleware = async (req, res) => {
const lines = [];
const lineProcesser = ({ name, filename, type, lineNumber, line }) => lines.push(line);
await textReadline(req, lineProcesser);
...
}
const textReadline = require('text-readline');
...
const middleware = async (req, res) => {
const lines = [];
const lineProcesser = ({ name, filename, type, lineNumber, line }) => lines.push(line);
const filter = 'form-key'
await textReadline(req, filter, lineProcesser);
...
}
const textReadline = require('text-readline');
...
const middleware = async (req, res) => {
const lines = [];
const lineProcesser = ({ name, filename, type, lineNumber, line }) => lines.push(line);
const filter = { name: 'form-key', filename: 'mylog.log', type: 'plain' };
await textReadline(req, filter, lineProcesser);
...
}
const textReadline = require('text-readline');
...
const middleware = async (req, res) => {
const lines = [];
const lineProcesser = ({ name, filename, type, lineNumber, line }) => lines.push(line);
const filter = { index: 0 };
await textReadline(req, filter, lineProcesser);
...
}
const textReadline = require('text-readline');
...
const middleware = async (req, res) => {
const lines = [];
const lineProcesser = ({ name, filename, type, lineNumber, line }) => lines.push(line);
const filter = { type: 'plain' };
const filter2 = { type: 'markdown' };
textReadline(req, filter, lineProcesser);
await textReadline(req, filter2, lineProcesser);
...
}