index.js
function promiseNodeify(promise, callback) {
  if (typeof callback !== 'function') {
    return promise;
  }

  function onRejected(reason) {
    // callback is unlikely to recognize or expect a falsey error.
    // (we also rely on truthyness for arguments.length in doCallback)
    // Convert it to something truthy
    let truthyReason = reason;
    if (!truthyReason) {
      // Note:  unthenify converts falsey rejections to TypeError:
      // https://github.com/blakeembrey/unthenify/blob/v1.0.0/src/index.ts#L32
      // We use bluebird convention for Error, message, and .cause property
      truthyReason = new Error(String(reason));
      truthyReason.cause = reason;
    }

    doCallback(callback, truthyReason);
  }

  function onResolved(value) {
    doCallback(callback, null, value);
  }

  promise.then(onResolved, onRejected);
  return undefined;
}
function promiseNodeify(promise, callback) {
  if (typeof callback !== 'function') {
    return promise;
  }

  function onRejected(reason) {
    // callback is unlikely to recognize or expect a falsey error.
    // (we also rely on truthyness for arguments.length in doCallback)
    // Convert it to something truthy
    let truthyReason = reason;
    if (!truthyReason) {
      // Note:  unthenify converts falsey rejections to TypeError:
      // https://github.com/blakeembrey/unthenify/blob/v1.0.0/src/index.ts#L32
      // We use bluebird convention for Error, message, and .cause property
      truthyReason = new Error(String(reason));
      truthyReason.cause = reason;
    }

    doCallback(callback, truthyReason);
  }

  function onResolved(value) {
    doCallback(callback, null, value);
  }

  promise.then(onResolved, onRejected);
  return undefined;
}
function promiseNodeify ( promise , callback ) { if ( typeof callback !== 'function' ) { return promise ; } function onRejected ( reason ) { // callback is unlikely to recognize or expect a falsey error. // (we also rely on truthyness for arguments.length in doCallback) // Convert it to something truthy let truthyReason = reason ; if ( ! truthyReason ) { // Note:  unthenify converts falsey rejections to TypeError: // https://github.com/blakeembrey/unthenify/blob/v1.0.0/src/index.ts#L32 // We use bluebird convention for Error, message, and .cause property truthyReason = new Error ( String ( reason ) ) ; truthyReason . cause = reason ; } doCallback ( callback , truthyReason ) ; } function onResolved ( value ) { doCallback ( callback , null , value ) ; } promise . then ( onResolved , onRejected ) ; return undefined ; }
Calls a node-style callback when a Promise is resolved or rejected.

This function provides the behavior of
{@link https://github.com/then/nodeify then <code>nodeify</code>},
{@link
https://github.com/cujojs/when/blob/master/docs/api.md#nodebindcallback
when.js <code>node.bindCallback</code>},
or {@link http://bluebirdjs.com/docs/api/ascallback.html bluebird
<code>Promise.prototype.nodeify</code> (now
<code>Promise.prototype.asCallback</code>)} (without options).

@ template ValueType
@param {!Promise<ValueType>} promise Promise to monitor.
@param {?function(*, ValueType=)=} callback Node-style callback to be
called when <code>promise</code> is resolved or rejected.  If
<code>promise</code> is rejected with a falsey value the first argument
will be an instance of <code>Error</code> with a <code>.cause</code>
property with the rejected value.
@return {Promise<ValueType>|undefined} <code>undefined</code> if
<code>callback</code> is a function, otherwise a <code>Promise</code>
which behaves like <code>promise</code> (currently is <code>promise</code>,
but is not guaranteed to remain so).
@alias module:promise-nodeify
Calls a node - style callback when a Promise is resolved or rejected .