Skip to content

Instantly share code, notes, and snippets.

What would you like to do?

NodeJS File parsing

Here's a skelleton for ripping files apart in NodeJS and processing each line.

var fs = require('fs');
var zlib = require('zlib');
var stream = require('stream');
var es = require('event-stream');

var return_object = {
  logs: []

// Create a readStream object...
  // Do something when done processing the file.
  .on('end', function(){
  // If it's a gzip, ungzip it on the fly.
  // Split on \n
  // Now, do something with each line.
  .pipe(, callback){
      // in my case I have a line parse function elsewhere in the script.
      my.parse(data, function(error, object){
        if ( error ) {
        } else {
          // And I have a filter function as well to rate logs.
          my.filter(object, 70, function(error, log){
            if ( error ) {
            } else {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.