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 1306052 85184 ?       Ssl   2025 1332:09 node /home/sasa/.pm2/modules/pm2-logrotate/node_modules/pm2-logr
sasa        1208  0.3  0.4 1303464 72028 ?       Ssl   2025 959:34 node /home/sasa/dex8/dex8-panel/server/index.js
sasa        1236  0.5  0.6 11819860 106988 ?     Ssl   2025 1517:11 node /home/sasa/mikosoft_hr/www-mikosoft-hr/server/index.js
sasa        1257  0.3  0.4 1304920 73876 ?       Ssl   2025 973:27 node /home/sasa/mikosoft-info/www-mikosoft-info/server/index.js
sasa        1289  0.3  0.4 1297836 68288 ?       Ssl   2025 958:14 node /home/sasa/dex8/dex8-kiosk/server/index.js
sasa        1363  4.5  2.7 12148348 452200 ?     Ssl   2025 12431:59 node /home/sasa/voovuu/voovuu-pub/server/index.js
sasa        1886  4.1  2.8 12132020 467936 ?     Ssl   2025 11445:03 node /home/sasa/mikosoft-info/crypto-mikosoft-info/server/index.
sasa     1214480  0.3  0.7 22311168 125932 ?     Ssl   2025 692:48 node /home/sasa/dex8/dex8-worker/starter.js
sasa     1214483  0.3  0.4 1103104 67248 ?       Ssl   2025 610:55 node /home/sasa/dex8/dex8-worker/starter.js
sasa     1214536  0.3  0.4 1100804 65824 ?       Ssl   2025 609:36 node /home/sasa/dex8/dex8-worker/starter.js
sasa     1214544  0.3  0.3 1101032 65352 ?       Ssl   2025 613:57 node /home/sasa/dex8/dex8-worker/starter.js
sasa     1214588  0.3  0.3 1100548 65084 ?       Ssl   2025 610:54 node /home/sasa/dex8/dex8-worker/starter.js
sasa     1214617  0.3  0.4 1100672 66376 ?       Ssl   2025 609:18 node /home/sasa/dex8/dex8-worker/starter.js
sasa     1214641  0.3  0.3 1100648 64552 ?       Ssl   2025 600:21 node /home/sasa/dex8/dex8-worker/starter.js
sasa     1214671  0.3  0.3 1100128 63280 ?       Ssl   2025 598:09 node /home/sasa/dex8/dex8-worker/starter.js
sasa     1215731  0.6  0.7 11710144 124340 ?     Ssl   2025 1184:37 node /home/sasa/dex8/dex8-api/starter.js
sasa     1216489  0.3  0.3 1100792 65392 ?       Ssl   2025 608:44 node /home/sasa/dex8/dex8-worker/starter.js
sasa     1399960  0.9  0.7 11828828 115064 ?     Ssl  Apr20 154:59 node /home/sasa/dex8/dex8-www/server/index.js
sasa     1904154  0.5  0.6 11834320 108368 ?     Ssl  Apr25  61:32 node /home/sasa/miko/miko-hr/server/index.js
sasa     2628167  0.8  0.8 1176408 131316 ?      Ssl   2025 2179:37 node /home/sasa/voovuu/voovuu-api/starter.js
sasa     2646998  0.3  0.3 1100188 63084 ?       Ssl  04:03   2:02 node /home/sasa/dex8/dex8-worker/starter.js
www-data 2695553  0.0  0.0   2608   596 ?        S    14:23   0:00 sh -c ps -aux | grep node
www-data 2695555  0.0  0.0   3304   724 ?        S    14:23   0:00 grep node
sasa     3168557  0.6  0.5 11822784 97472 ?      Ssl   2025 1580:57 node /home/sasa/mikosoft-info/dodo-mikosoft-info/server/index.js
sasa     3169051  0.5  0.5 11799176 83648 ?      Ssl   2025 1308:24 node /home/sasa/@mikosoft/dodo-examples/server/index.js
sasa     3264954  0.7  0.5 1332748 86148 ?       Ssl  Feb21 704:53 node /home/sasa/mikosoft-info/api-mikosoft-info/starter.js