I'm unclear on what the .pipe() function does in node?
How could I use it to refactor any of the two functions below?
exports.collectData = function(req, callback) { var data = ""; req.on("data", function(chunk) { data += chunk; }) req.on("end", function() { callback(data); }) } http.createServer(function(req, res){ res.writeHead(200, {"Content-type": "text/plain"}); res.write("Howdy"); res.end(); }).listen(port); //new code from answer:
var fs = require("fs"); // Read File fs.createReadStream("input/people.json") // Write File .pipe(fs.createWriteStream("output/people.json"));