Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

readfileline

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

readfileline

read file line by line

  • 2.0.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

ReadFileLine

Read file line by line for node

Build Status Build status

Install

$ npm install readfileline -g

How to use



var fl = require('readfileline');
var fileContents = [];
fl(__dirname+'/data.txt',function(lineData,lineNum){
    fileContents.push(lineData);
    console.log(lineNum+':'+lineData+'\n');
},function(err,eventType,totalLineNum){
    if(eventType=='end'){
    	//if file read all line to success, "close" event still will emit, so you need distinguish between they
    	console.log('read line is done, total '+totalLineNum+' line(s)');
    }
	if(eventType=='close'){
		console.log('read line is closed, read to '+totalLineNum+' line(s)');
	}
    if(eventType=='error'){
    	console.log('read file line has an error:'+err.message);
    }
});

//--------

var fileContents2=[];
fl(__dirname+'/data.txt',function(lineData,lineNum){
	var thisFL = this;
	if(lineNum>=5){
		this.close(); //And also has a function is "this.stop()", but it still emit "close" event so you still need listen "close" event, so mustn't listen "stop" event
		return;
	}
    fileContents2.push(lineData);
    console.log(lineNum+':'+lineData+'\n');
},function(err,eventType,totalLineNum){
    if(eventType=='end'){
    	//if file read all line to success, "close" event still will emit, so you need distinguish between they
    	console.log('read line is done, total '+totalLineNum+' line(s)');
    }
	if(eventType=='close'){
		console.log('read line is closed, read to '+totalLineNum+' line(s)');
	}
    if(eventType=='error'){
    	console.log('read file line has an error:'+err.message);
    }
});

Keywords

FAQs

Package last updated on 10 Jul 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc