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.4  0.5 1305096 83980 ?       Ssl   2025 1438:02 node /home/sasa/.pm2/modules/pm2-logrotate/node_modules/pm2-logr
sasa        1208  0.3  0.4 1304232 72004 ?       Ssl   2025 1022:46 node /home/sasa/dex8/dex8-panel/server/index.js
sasa        1236  0.5  0.6 11821608 107184 ?     Ssl   2025 1616:06 node /home/sasa/mikosoft_hr/www-mikosoft-hr/server/index.js
sasa        1257  0.3  0.4 1304920 72776 ?       Ssl   2025 1037:10 node /home/sasa/mikosoft-info/www-mikosoft-info/server/index.js
sasa        1289  0.3  0.4 1298340 68596 ?       Ssl   2025 1021:25 node /home/sasa/dex8/dex8-kiosk/server/index.js
sasa        1363  4.5  2.9 12179524 489572 ?     Ssl   2025 13319:06 node /home/sasa/voovuu/voovuu-pub/server/index.js
sasa        1886  4.6  3.3 12212268 555276 ?     Ssl   2025 13535:37 node /home/sasa/mikosoft-info/crypto-mikosoft-info/server/index.
www-data   37877  0.0  0.0   2608   524 ?        S    14:44   0:00 sh -c ps -aux | grep node
www-data   37879  0.0  0.0   3304   648 ?        S    14:44   0:00 grep node
sasa     1214480  0.3  0.7 22311168 125372 ?     Ssl   2025 763:19 node /home/sasa/dex8/dex8-worker/starter.js
sasa     1214483  0.3  0.4 1101312 66112 ?       Ssl   2025 678:13 node /home/sasa/dex8/dex8-worker/starter.js
sasa     1214536  0.3  0.4 1101572 66572 ?       Ssl   2025 676:44 node /home/sasa/dex8/dex8-worker/starter.js
sasa     1214544  0.3  0.4 1101032 65568 ?       Ssl   2025 681:49 node /home/sasa/dex8/dex8-worker/starter.js
sasa     1214588  0.3  0.3 1101060 65072 ?       Ssl   2025 678:21 node /home/sasa/dex8/dex8-worker/starter.js
sasa     1214617  0.3  0.4 1102464 67628 ?       Ssl   2025 676:21 node /home/sasa/dex8/dex8-worker/starter.js
sasa     1214641  0.3  0.4 1168232 66728 ?       Ssl   2025 666:28 node /home/sasa/dex8/dex8-worker/starter.js
sasa     1214671  0.3  0.3 1100384 65184 ?       Ssl   2025 664:08 node /home/sasa/dex8/dex8-worker/starter.js
sasa     1215731  0.7  0.7 11845212 128704 ?     Ssl   2025 1472:26 node /home/sasa/dex8/dex8-api/starter.js
sasa     1216489  0.3  0.3 1101560 65380 ?       Ssl   2025 675:47 node /home/sasa/dex8/dex8-worker/starter.js
sasa     1399960  0.8  0.7 11825756 115372 ?     Ssl  Apr20 324:14 node /home/sasa/dex8/dex8-www/server/index.js
sasa     1904154  0.6  0.6 11829500 106752 ?     Ssl  Apr25 186:47 node /home/sasa/miko/miko-hr/server/index.js
sasa     2628167  0.8  0.8 1176920 132816 ?      Ssl   2025 2328:28 node /home/sasa/voovuu/voovuu-api/starter.js
sasa     3168557  0.6  0.5 11823304 97504 ?      Ssl   2025 1699:37 node /home/sasa/mikosoft-info/dodo-mikosoft-info/server/index.js
sasa     3169051  0.5  0.5 11799176 84312 ?      Ssl   2025 1409:14 node /home/sasa/@mikosoft/dodo-examples/server/index.js
sasa     3264954  0.7  0.5 1332492 87320 ?       Ssl  Feb21 851:59 node /home/sasa/mikosoft-info/api-mikosoft-info/starter.js
sasa     4183634  0.3  0.3 1098852 62868 ?       Ssl  04:03   2:05 node /home/sasa/dex8/dex8-worker/starter.js