Created
November 15, 2012 22:23
-
-
Save chartjes/4081814 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require('fs'); | |
var stream = fs.createReadStream('./test/fixtures/current'); | |
var currentData = ''; | |
stream.on('error', function (err) { | |
throw err; | |
}); | |
stream.on('data', function (data) { | |
currentData += data; | |
}); | |
// I want currentData to contain the contents of my file but | |
// console.log(currentData) shows nothing is in there. | |
// what am I missing? | |
console.log(currentData); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You'll have to put the console.log inside of the event listener:
The current call to console.log executes on a separate path, probably before a data event is generated.
If you are just try to collect all the output of that file/pipe, you could use one of the blocking fs functions, such as fs.readFileSync