Skip to content

Instantly share code, notes, and snippets.

@eiriklv
Forked from LewisJEllis/gist:1ac2e10e9309b3f59017
Last active August 29, 2015 14:13
Show Gist options
  • Save eiriklv/1c3e6a6534fd6fb499a2 to your computer and use it in GitHub Desktop.
Save eiriklv/1c3e6a6534fd6fb499a2 to your computer and use it in GitHub Desktop.
var express = require('express');
var _ = require('highland');
var fs = require('fs');
var app = express();
function chain(s, f) {
return s.flatMap(_.wrapCallback(f))
}
app.post('/process-file', function(req, res) {
var inputFile = 'input.txt';
var outputFile = 'output.txt';
var data = _([inputFile]);
_([
fs.readFile,
process1,
process2,
process3,
writeToFileName(outputFile)
]).reduce(data, chain).flatten()
.stopOnError(function (err) {
return res.status(500).send(err);
}).apply(function (data) {
return res.status(200).send('processed');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment