Tutorial by Examples

One of the best features of async/await syntax is that standard try-catch coding style is possible, just like you were writing synchronous code. const myFunc = async (req, res) => { try { const result = await somePromise(); } catch (err) { // handle errors here } }); Here'...
Function using promises: function myAsyncFunction() { return aFunctionThatReturnsAPromise() // doSomething is a sync function .then(result => doSomething(result)) .catch(handleError); } So here is when Async/Await enter in action in order to get clean...
In the beginning there were callbacks, and callbacks were ok: const getTemperature = (callback) => { http.get('www.temperature.com/current', (res) => { callback(res.data.temperature) }) } const getAirPollution = (callback) => { http.get('www.pollution.com/current', (res) ...
If the promise doesn't return anything, the async task can be completed using await. try{ await User.findByIdAndUpdate(user._id, { $push: { tokens: token } }).exec() }catch(e){ handleError(e) }

Page 1 of 1