News for hackers. Stuff that matters.
Re:Understanding Node.js Event-Driven Architecture by Klathmon on Monday May 08, 2017 @09:19AM (#14291195)
The situation is still that callbacks are king in the node core libraries. But there is some talk about how to move forward[0], however I don't think there has been much headway as of the last time I really looked into it about 6-months ago.

That being said, there are some fantastic libraries which you can use as a drop-in replacement for the core libraries provide a promise based API, but nothing in core directly.

[0] https://github.com/nodejs/NG/issues/25

Re:Understanding Node.js Event-Driven Architecture by gotchange on Monday May 08, 2017 @09:30AM (#14291269)
Can you recommend please some of these non CB based libraries?
Re:Understanding Node.js Event-Driven Architecture by Klathmon on Monday May 08, 2017 @09:49AM (#14291397)
The only one i've used before is Bluebird's `promisifyAll` method.

So when you require libraries, you can do so like:

    const fs = Promise.promisifyAll(require('fs'))
    // ... later    
    const fileContents = await fs.readFileAsync('filename.txt')
Basically it just adds "Async" after all functions that use node style callbacks.
Re:Understanding Node.js Event-Driven Architecture by shawndellysse on Tuesday May 09, 2017 @11:02AM (#14300610)
mz (https://www.npmjs.com/package/mz) is my go-to. You just prefix the core lib ("fs") with "mz/" ("mz/fs") and you get the promised version.

    const fs = require("fs");
    fs.exists(`${ __dirname }/1`, (exists1) => {
      fs.exists(`${ __dirname }/2`, (exists2) => {
        console.log(JSON.stringify([exists1, exists2]));
      });
    });
vs

    const fs = require("mz/fs");
    Promise.all([
      fs.exists(`${ __dirname }/1`),
      fs.exists(`${ __dirname }/2`),
    ])
    .then((existers) => {
      console.log(JSON.stringify(existers));
    });
Or

    const fs = require("mz/fs");
    (async () => {
      console.log(JSON.stringify(await Promise.all([
        fs.exists(`${ __dirname }/1`),
        fs.exists(`${ __dirname }/2`),
      ])));
    })();
Re:Understanding Node.js Event-Driven Architecture by karmelapple on Monday May 08, 2017 @09:50AM (#14291405)
supertest-as-promised is pretty great for testing purposes.
Re:Understanding Node.js Event-Driven Architecture by mikewhy on Tuesday May 09, 2017 @10:09AM (#14300100)
Regular supertest supports promises.