Speed up development with full-stack environments for every branch.

Learn More

A clean way to promisify callback functions [Node.js, nodejitsu, npmawesome, promises and bluebird]

Forked from Hello World for Node.js.

128 Runs 2777 Views 57 Copies

This example shows the usage of Songbird module which wraps Bluebird and give a very clean `promise` property on all callback style functions.



alexgorbatchev 28

published 3 years ago

var Promise = require('songbird');
var fs = require('fs');

// callback API
fs.readFile('./package.json', 'utf8', function(err, pkg) {
  console.log('callbacks', pkg);

// songbird API
fs.promise.readFile('./package.json', 'utf8').then(function(pkg) {
  console.log('promise', pkg);

    fs.promise.readFile('./package.json', 'utf8'),
    fs.promise.readFile('./songbird.js', 'utf8')
  .spread(function(pkg, songbird) {
    console.log('package.json length is', pkg.length);
    console.log('songbird.js length is', songbird.length);
Please login/signup to get access to the terminal.

Your session has timed out.

Dismiss (the page may not function properly).