O'Reilly logo
live online training icon Live Online training

Asynchronous Programming with Node.js

Core Node features that enable high-volume, scalable applications

Chetan Karande

The asynchronous execution model is at the heart of Node.js’s 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. Node.js developers have to embrace asynchronous programming to build modern large-scale applications on this platform. However, the steep learning curve and related pitfalls often intimidate and trip them up, causing applications to crash because of unhandled errors or difficult-to-detect memory leaks.

Expert Chetan Karande demystifies the asynchronous programming constructs offered by JavaScript and Node.js APIs, including callbacks, Promises, async and await, async iterators, async generators, and streams. By the time you’re done, you’ll have learned the practical skills you need to be an effective Node.js developer.

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 of memory leaks associated with asynchronous code
  • Relatively new JavaScript language features such as the async iterator and async generator

And you’ll be able to:

  • Write asynchronous programs in a maintainable and comprehensible way
  • Handle runtime errors
  • Use powerful Node.js streams to process large amounts of data effectively

This training course is for you because...

  • You’re a web developer with proficiency in JavaScript who wants to expand your knowledge of Node.js beyond the basics.
  • You already work with Node.js but need to understand the newer asynchronous APIs.

Prerequisites

  • A working understanding of JavaScript
  • Experience developing Node.js applications

Recommended preparation:

Recommended follow-up:

About your instructor

  • Chetan Karande is a full stack web developer, security researcher, author, and trainer. He’s the author of Securing Node Applications (O’Reilly). He’s also the project leader for the OWASP NodeGoat project, an open source platform to learn about Node.js security, and a contributor to multiple open source projects.

Schedule

The timeframes are only estimates and may vary according to how the class is progressing

Introduction (20 minutes)

  • Group discussion: Your experience with Node.js
  • Lecture: Node.js architecture choices; processing I/O, memory, and CPU-intensive operations

Mechanisms for handling I/O operations (40 minutes)

  • Lecture: Node.js event loop and I/O execution mechanism using native OS async features and libuv thread pool; asynchronous programming mechanisms
  • Hands-on exercise: Error handling implementation for an I/O operation
  • Q&A

Break (5 minutes)

Mechanisms for handling memory-intensive operations (50 minutes)

  • Lecture: Node.js stream types and controls that allow limiting memory usage while data is processing; Node streams with async generator and async iterator
  • Hands-on exercise: Use stream API to optimize memory use
  • Q&A

Break (5 minutes)

Mechanisms for handling-CPU intensive operations (30 minutes)

  • Lecture: Executing tasks in parallel with the multicore system with worker thread and child_process APIs
  • Hands-on exercise: Optimize CPU core use
  • Q&A

Mechanisms for implementing asynchronous logic (20 minutes)

  • Lecture: Order of execution among Node.js timer APIs, Promises, and process.nextTick(); related queues and event loop execution phases; pitfalls-related resource starvation
  • Hands-on exercise: Identify the order of execution of asynchronous functions
  • Q&A

Wrap-up and Q&A (10 minutes)