Asynchronous Programming with Node.js
Exploring the core Node features that enable high-volume, scalable applications
The asynchronous execution model is at the heart of Node.js internal architecture, enabling it to handle thousands of concurrent requests with a single CPU core, and process gigabytes of data with a tiny amount of RAM. Embracing the craft of asynchronous programming is therefore essential for Node.js developers for building modern large-scale applications on this platform. However, the related concepts could be intimidating due to a steep learning curve and related pitfalls often trip up developers causing applications to crash due to unhandled errors or difficult to detect memory leaks.
- async iterator
- async generator
Learners will discover the practical skills needed to be effective Node.js developers.
What you'll learn-and how you can apply it
By the end of this live, hands-on, online course, you’ll understand:
- the pitfalls related to memory leaks associated with the asynchronous code
And you’ll be able to:
- write asynchronous programs in a maintainable and comprehensible way
- handle runtime errors gracefully from the asynchronous code
- effectively use powerful Node.js streams to process large amount of data
This training course is for you because...
- You already work with Node.js but need to understand the newer asynchronous APIs
- Verify that you have the latest LTS version of Node.js or above installed locally, as well as Visual Studio Code (or another IDE of your choice) and Git.
- Read Node Cookbook, Third Edition (book), which covers a wide range of scenarios and solutions using Node.js
About your instructor
Chetan Karande is a full stack web developer, security researcher, author, speaker at developer conferences. He is the author of Securing Node Applications (O’Reilly). He is the project leader for the OWASP NodeGoat project and contributor to multiple open source projects.
The timeframes are only estimates and may vary according to how the class is progressing
Opening (20 minutes)
- Presentation: Review Node.js architecture choices and its implications on processing I/O, memory, and CPU intensive operations
Mechanisms for handling I/O operations (40 minutes)
- Presentation: Overview of Node.js event loop and I/O execution mechanism using native OS async features and libuv Thread pool
- Presentation: Asynchronous programming mechanisms: callbacks, promises, async functions and common coding pitfalls related to each
- Exercise: Fix error handling implementation for an I/O operation
- Break (5 minutes)
Mechanisms for handling memory intensive operations (50 minutes)
- Presentation: Review of Node.js stream types and controls that allow limiting memory usage while data processing
- Presentation: Using Node streams with async generator and async iterator
- Exercise: Fix the code to use stream API to optimize memory utilization
- Break (5 minutes)
Mechanisms for handling CPU intensive operations (30 minutes)
- Presentation: Utilizing the multi-core system using worker thread and child_process APIs to execute tasks in parallel
- Exercise: Fix the code to optimize CPU core utilization
Mechanisms for implementing asynchronous logic (20 minutes)
- Presentation: Order of execution among Node.js timer APIs, promises, and process.nextTick(); related queues and event loop execution phases
- Presentation: Pitfalls related resource starvation associated with micro task queues prioritization and memory usage
- Exercise: Identify the order of execution of asynchronous functions
Recap, further learning, and wrap-up (10 minutes)