The Callback Pattern: Node.js Conventions

Learn about Node.js conventions in the callback pattern.

In Node.js, CPS APIs and callbacks follow a set of specific conventions. These conventions apply to the Node.js core API, but they’re also followed by the vast majority of the userland modules and applications. So, it’s very important that we understand them and make sure that we comply whenever we need to design an asynchronous API that makes use of callbacks.

The callback comes last

In all core Node.js functions, the standard convention is that when a function accepts a callback as input, this has to be passed as the last argument.

Let’s take the following Node.js core API as an example:

Create a free account to view this lesson.

By signing up, you agree to Educative's Terms of Service and Privacy Policy