promise - Chain parameters between async functions with Q in node.js -


how can chain parameters need both async functions.

the first function fs.readfile returns content of file in callback function second parameter.

the second function marked requires content first parameter. second parameter optional , can options object. third parameter callback should give me converted content second parameter.

currently i've tried code:

  var readfile = q.nfbind(fs.readfile);   var md = q.nfbind(marked);    readfile(filename, 'utf8')   .then(md)   .then(function (html) {     res.setheader('content-type', 'text/html');     res.setheader('content-length', html.length);     res.status(200);     res.end(html);   })   .catch(function (error) {     res.setheader('content-type', 'text/plain');     res.send(500, 'server error: ' + error);     res.end();   })   .done(); 

but doesn't work, because marked function needs second parameter when called callback function third parameter. how can set second parameter, call marked function correctly?

if replace .then(md) line .then(marked), result of calling fs.readfile (the value promise fulfilled) passed marked.


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

node.js - Node - Passport Auth - Authed Post Route hangs on form submission -

Does Firefox offer AppleScript support to get URL of windows? -