Test JS script file

Selected file: 50bluebird_newPromise.js
Compare console.log() outputs in browser and NodeJS.
Notice: Open browser's console in FireBUG!

  1. 01callback.js
  2. 02callback_settimeout.js
  3. 02callback_settimeout2.js
  4. 50bluebird_basic.js
  5. 50bluebird_newPromise.js
  6. 51bluebird_fs.js

..:: Source code - 50bluebird_newPromise.js ::..

/**
 * basic usage of bluebird
 */

var Promise = require("bluebird");

//defining an async function
var clAsync = function () {
  var P = new Promise(function (resolve, reject) {
    console.log('Write from function');
    resolve('ok');
    reject('not ok');
  });

  /*
  {
  "isFulfilled": true,
  "isRejected": false,
  "fulfillmentValue": "ok"
  }
   */
  console.log(JSON.stringify(P, null, 2));

  return P;
};

console.log(JSON.stringify(clAsync, null, 2)); //undefined

//executing promisified function clAsync() and adding new callback with then method
clAsync()

  .then(function (returnedVal) {
    console.log('THEN 1 - fulfillmentValue= ' + returnedVal);
    return {one: 1, two: 'drugi'}; //returning to next then
  })

  .then(function (returnedVal) {
    console.logs('THEN 2 - fulfillmentValue= ' + returnedVal.one + returnedVal.two);
    // return new Error('Namjerna greška');  --doesn't work
    throw new Error('Namjerna greška', 'someFile.js', 152);
  })

  //catch type errors
  .catch(TypeError, function (e) {
    console.error(e.stack);
    // console.error(e.message);
  })

  //catch all other errors
  .catch(function (e) {
    console.error(e.message);
    // console.error(e.stack);
  });
 

..:: NodeJS Console - 50bluebird_newPromise.js ::..

$ node 50bluebird_newPromise.js

		
		
$ps -aux | grep node (list all node processes)
sasa        1194  0.5  0.5 1305876 86444 ?       Ssl   2025 1114:49 node /home/sasa/.pm2/modules/pm2-logrotate/node_modules/pm2-logr
sasa        1208  0.3  0.4 1304744 72696 ?       Ssl   2025 801:07 node /home/sasa/dex8/dex8-panel/server/index.js
sasa        1224  0.7  0.6 11822652 112124 ?     Ssl   2025 1772:42 node /home/sasa/dex8/dex8-www/server/index.js
sasa        1236  0.5  0.6 11821584 109052 ?     Ssl   2025 1267:31 node /home/sasa/mikosoft_hr/www-mikosoft-hr/server/index.js
sasa        1257  0.3  0.4 1304408 73132 ?       Ssl   2025 813:07 node /home/sasa/mikosoft-info/www-mikosoft-info/server/index.js
sasa        1289  0.3  0.4 1297836 68372 ?       Ssl   2025 799:40 node /home/sasa/dex8/dex8-kiosk/server/index.js
sasa        1363  4.5  2.9 12188072 475164 ?     Ssl   2025 10096:13 node /home/sasa/voovuu/voovuu-pub/server/index.js
sasa        1886  3.3  2.2 12038624 365704 ?     Ssl   2025 7559:55 node /home/sasa/mikosoft-info/crypto-mikosoft-info/server/index.
sasa     1214480  0.3  0.7 22311168 126252 ?     Ssl   2025 515:00 node /home/sasa/dex8/dex8-worker/starter.js
sasa     1214483  0.3  0.3 1101568 65252 ?       Ssl   2025 441:34 node /home/sasa/dex8/dex8-worker/starter.js
sasa     1214536  0.3  0.4 1101060 65892 ?       Ssl   2025 440:25 node /home/sasa/dex8/dex8-worker/starter.js
sasa     1214544  0.3  0.4 1101544 66840 ?       Ssl   2025 443:29 node /home/sasa/dex8/dex8-worker/starter.js
sasa     1214588  0.3  0.4 1102084 65888 ?       Ssl   2025 441:27 node /home/sasa/dex8/dex8-worker/starter.js
sasa     1214617  0.3  0.4 1100928 66300 ?       Ssl   2025 440:15 node /home/sasa/dex8/dex8-worker/starter.js
sasa     1214641  0.3  0.3 1100648 65100 ?       Ssl   2025 433:54 node /home/sasa/dex8/dex8-worker/starter.js
sasa     1214671  0.3  0.3 1100128 63428 ?       Ssl   2025 432:14 node /home/sasa/dex8/dex8-worker/starter.js
sasa     1215731  0.7  0.7 11709320 123292 ?     Ssl   2025 904:52 node /home/sasa/dex8/dex8-api/starter.js
sasa     1216489  0.3  0.3 1101816 65340 ?       Ssl   2025 439:48 node /home/sasa/dex8/dex8-worker/starter.js
sasa     2509059  0.5  0.5 11803152 94144 ?      Ssl  Feb14 351:26 node /home/sasa/miko/miko-hr/server/index.js
sasa     2628167  0.8  0.8 1177176 132696 ?      Ssl   2025 1792:26 node /home/sasa/voovuu/voovuu-api/starter.js
sasa     2965845  0.3  0.3 1098848 63068 ?       Ssl  03:03   0:52 node /home/sasa/dex8/dex8-worker/starter.js
www-data 2987973  0.0  0.0   2608   528 ?        S    07:34   0:00 sh -c ps -aux | grep node
www-data 2987975  0.0  0.0   3304   720 ?        S    07:34   0:00 grep node
sasa     3168557  0.6  0.5 11801232 90484 ?      Ssl   2025 1284:01 node /home/sasa/mikosoft-info/dodo-mikosoft-info/server/index.js
sasa     3169051  0.5  0.5 11799176 84784 ?      Ssl   2025 1054:40 node /home/sasa/@mikosoft/dodo-examples/server/index.js
sasa     3264954  0.6  0.5 1330960 85716 ?       Ssl  Feb21 324:45 node /home/sasa/mikosoft-info/api-mikosoft-info/starter.js