Koa / Co / Bluebird or Q / Generators / Promises / Thunks interplay? (Node.js) [closed]

I’ve been working almost extensively with generators for a month now so maybe I can take a stab at this. I’ll try to keep the opinions to a minimum. Hopefully it helps clarify some of the confusion. Part of the reason for the lack of best practices and better explanations is that the feature is … Read more

Catching Errors in JavaScript Promises with a First Level try … catch

You cannot use try-catch statements to handle exceptions thrown asynchronously, as the function has “returned” before any exception is thrown. You should instead use the promise.then and promise.catch methods, which represent the asynchronous equivalent of the try-catch statement. (Or use the async/await syntax noted in @Edo’s answer.) What you need to do is to return … Read more

Promise.resolve vs new Promise(resolve)

Contrary to both answers in the comments – there is a difference. While Promise.resolve(x); is basically the same as new Promise(function(r){ r(x); }); there is a subtlety. Promise returning functions should generally have the guarantee that they should not throw synchronously since they might throw asynchronously. In order to prevent unexpected results and race conditions … Read more

How to promisify Node’s child_process.exec and child_process.execFile functions with Bluebird?

I would recommend using standard JS promises built into the language over an additional library dependency like Bluebird. If you’re using Node 10+, the Node.js docs recommend using util.promisify which returns a Promise<{ stdout, stderr }> object. See an example below: const util = require(‘util’); const exec = util.promisify(require(‘child_process’).exec); async function lsExample() { try { … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)