Created
January 28, 2015 13:32
-
-
Save skrat/d2bfd58201eeed13a377 to your computer and use it in GitHub Desktop.
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
var express = require('express'); | |
var Promise = require("bluebird"); | |
var fs = Promise.promisifyAll(require('fs')); | |
var app = express(); | |
function pipe() { | |
return [].reduce.call(arguments, function(red, p) { | |
return red.then(p); | |
} | |
} | |
app.post('/process-file', function(req, res) { | |
var inputFile = 'input.txt'; | |
var outputFile = 'output.txt'; | |
pipe( fs.readFileAsync(inputFile), | |
process1, | |
process2, | |
process3, | |
fs.writeFileAsync.bind(fs, outputFile), | |
function(data) { | |
res.status(200).send('processed successfully using bluebird promises'); | |
} | |
).catch(function(err) { | |
res.status(500).send(err); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment