readl
Read a file line-by-line in node.js
Install
You can install the latest version of the package using npm:
$ npm install --save readl
Usage
//Import dependenciesvar readl = ; //File contentvar content = ''; //Read the file; //Show the file contentconsole;
API
readl(file, options, callback)
Execute the callback
function one time for each line on the file
.
file
A string
with the path to the file.
options
An object
with the following options:
encoding
: set the encoding. Default:utf8
.emptyLines
: set it tofalse
if you want to omit the empty lines. Default:true
.start
: start position. Default is 0.chunk
: set the chunk size. Default is 1024.endl
: set the end-line character. Default is0x0a
.
callback
A function
that will be executed one time for each read line on the file. This function will pass the following arguments:
line
: astring
with the read line.index
: aninteger
with the line number. The line counter starts in 1.position_start
: aninteger
with the start position of the line in the file.position_end
: aninteger
with the end position of the line in the file.length
: aninteger
with the number of bytes read.
You can break the loop at a particular line by making the callback function return false
.
Related
- readl-async: asynchronous version of this module.
License
MIT © Josemi Juanes.