With the addition of async functions in JavaScript, our code is about to be dramatically simplified. You need to learn this new syntax now, even if you can’t use it just yet. And I’ll show you the benefits of this new syntax to get you started.
Callbacks First, Then Promises
When I’m looking at asynchronous JavaScript – network calls, file system, or whatever it may be – I don’t reach for promises, first. In fact, a promise is typically a last resort for me, relegated to specific scenarios. I don’t mean to say promises are not useful. They certainly are useful and they are a […]
Ending the Nested Tree of Doom with Chained Promises
Julia Jacobs recently asked a question in the WatchMeCode community slack, about some asynchronous code she wanted to clean up. In this question, she wanted to know of good options for restructuring deeply nested promises without introducing any new libraries. Would it be possible to clean up the code and only use ES6 features? It’s a common […]
In What Order Does My Express.js Middleware Execute?
I recently had a conversation in the WatchMeCode slack where someone was asking about the order in which various parts of Express middleware would fire. After some initial thoughts on the question, I found myself not 100% certain of the order between calls to “.use”, vs get/post/etc. So I whipped up a quick demo app […]
What Do You Name The Callback Function?
JavaScript practically requires callback functions to do anything asynchronous. Unless you’re talking about generators, you really can’t get away from them. Callbacks are everywhere. But someone recently asked a question about naming callback methods: Do you use different / standard callback names in different scenarios? For example, “next” for Express middleware, maybe “cb” or “callback” […]