Book Image

Learning Node.js for .NET Developers

Book Image

Learning Node.js for .NET Developers

Overview of this book

Node.js is an open source, cross-platform runtime environment that allows you to use JavaScript to develop server-side web applications. This short guide will help you develop applications using JavaScript and Node.js, leverage your existing programming skills from .NET or Java, and make the most of these other platforms through understanding the Node.js programming model. You will learn how to build web applications and APIs in Node, discover packages in the Node.js ecosystem, test and deploy your Node.js code, and more. Finally, you will discover how to integrate Node.js and .NET code.
Table of Contents (21 chapters)
Learning Node.js for .NET Developers
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

Combining asynchronous programming patterns


Promises allow us to address some of the shortcomings of the callback pattern and write more readable code. Now we have a new problem, though. One of the merits of Node.js is the consistent approach to asynchronous programming. We seem to have negated this by introducing promises as well as the conventional callback pattern.

Furthermore, although native promises are new to ECMAScript 2015, the concept is not new. There are many pre-existing libraries that provide their own implementation of promises.

Fortunately, these competing approaches to asynchronous programming are actually very consistent. The biggest value of the consistency in the Node.js-style callback pattern comes from the following:

  • All library functions are asynchronous (non-blocking) by default

  • All asynchronous operations return a single value or an error

Promises are completely consistent with the above points. There is also excellent compatibility between different implementations of...