Created
November 26, 2012 22:16
-
-
Save jessecravens/4151028 to your computer and use it in GitHub Desktop.
NodeJS Hacks - Streams - Web
This file contains hidden or 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
exports.example0 = function(req, res){ | |
var http = require('http'), | |
fs = require('fs'), | |
util = require('util'); | |
// Get html5hacks.com | |
require('http').get("http://html5hacks.com/", function(response) { | |
// The callback provides the response readable stream. | |
// Then, we open our output text stream. | |
var outStream = require('fs').createWriteStream("html5hacks.txt"); | |
// Pipe the input to the output, which writes the file. | |
response.pipe(outStream); | |
}); | |
res.render('example0', { title: 'Example0' }) | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment