---
title: "Asynchronous API"
description: "Learn how to use callbacks and Promises for asynchronous operations with the Aerospike Node.js client."
---

# Asynchronous API

> For the complete documentation index see: [llms.txt](https://aerospike.com/docs/llms.txt)
> 
> All documentation pages available in markdown.

The Aerospike Node.js client supports Node.js-style callbacks as well as Promises for all asynchronous database operations. This tutorial demonstrates both methods of asynchronous client operations.

### Example

This example demonstrates how to write a large set of records asynchronously. You can also use other database calls such as `Batch`, `Delete` and `Scan` asynchronously.

```js
import pLimit from "p-limit";

const Aerospike = await import("aerospike");

const limit = pLimit(100);

const recordMax = 100000;

// Set hosts to your server's address and port

 const config = { hosts: "YOUR_HOST_ADDRESS:YOUR_PORT" };

// Establishes a connection to the server

const client = await Aerospike.connect(config);

const promises = [];

for (let i = 0; i < recordMax; i++) {

  promises.push(

    limit(async () => {

      const key = new Aerospike.Key("test", "demo", i);

      const bins = { name: "example", age: 31, id: i };

      return client.put(key, bins);

    }),

  );

}

const results = await Promise.allSettled(promises);

for (const { status, reason } of results) {

  if (status === "rejected") {

    console.error("write failed with reason: \n" + reason);

  }

}

await client.close();
```