Last active
August 29, 2015 14:14
-
-
Save OdinsHat/49f856f0e451ae52cec9 to your computer and use it in GitHub Desktop.
Simply reads a file and outputs it to console.log/stdout
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 file = fs.createReadStream('origin.txt'); | |
var destFile = fs.createWriteStream('destination.txt'); | |
// Not surte why end: false required as it seems silly to close midway through copying? | |
file.pipe(destFile, {end: false}); | |
file.on('end', function(){ | |
destFile.end('Finished!'); | |
}); |
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
/** | |
* Sends index.html to request. | |
*/ | |
var fs = require('fs'); | |
var http = require('http'); | |
http.createServer(function(request, response) { | |
response.writeHead(200, {'Content-Type': 'text/html'}); | |
var file = fs.createReadStream('index.html'); | |
file.pipe(response, {end: false}); | |
}).listen(8080); |
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 file = fs.createReadStream('fruits.txt'); | |
file.pipe(process.stdout); |
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 file = new fs.createReadStream('fruits.txt'); | |
file.on('readable', function(){ | |
var chunk = null; | |
while(null !== (chunk = file.read())){ | |
console.log(chunk.toString()); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment