Quick question guys. I think i got the logic down but I am messed up because express doesnt have a pipe method?
anyways, I have this for my express endpoint
app.get('/:report/top', function(req, res) {
readDataTop(global[req.params.report], function(err, obj) {
res.header("Cache-Control", "max-age=3600");
res.json(obj);
});
});
and currently i am doing this to get data for it.
function readDataTop (x, callback) {
console.log("Read "+x[6]+" and Sent Cached Top Half");
jf.readFile( "loadedreports/top"+x[6], 'utf8', callback);
};
(jf just makes writing json.parse and with try/catch blocks easier) anyways I want to instead of just using fs.readfile i want to open a stream because these files are getting huge.
How would I pipe stuff to express but still use json? Something like this?
function readDataTop (x, callback) {
console.log("Read "+x[6]+" and Sent Cached Top Half");
var rstream = fs.createReadStream("loadedreports/top"+req.params.report+".json");
rstream.pipe(callback);
};
Any ideas? Req is undefined but I thought im passing it through the pipe correctly?