> For the complete documentation index, see [llms.txt](https://docs.keewano.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.keewano.com/sdks/nodejs.md).

# Node.js SDK

Report Keewano analytics from a server, on behalf of many users.

The Node.js SDK reports analytics from a **server, not a device**. One process relays events on behalf of many end users: for each user you assemble a self-contained batch, tag it with that user's id, and the SDK ships it. The wire format is identical to the React Native SDK, so the same backend ingests both.

It is the right fit for **server-authoritative events** — a purchase your backend validates, a subscription a billing webhook confirms, an item your economy service grants — that you want attributed to the user who triggered them.

## 1. Install

```bash
npm install @keewano/node-sdk
```

Requires Node.js 20 or newer (the SDK uses the built-in global `fetch`). There is no native code and no React dependency.

## 2. Initialize

Call `init` once when your process starts. It needs two things: your `apiKey`, and where to keep batches on disk — either a `dataDir` for the built-in storage or your own `storage` adapter.

```typescript
import { Keewano } from '@keewano/node-sdk';

await Keewano.init({
  apiKey: 'your-project-api-key',
  dataDir: '/var/lib/my-service/keewano',
});
```

{% hint style="danger" %}
**There is deliberately no default directory.** A queue holds batches addressed to one project, and each batch carries its own end user — so a process that finds a neighbour's file ships that neighbour's users into its own project.

Point `dataDir` at a private, persistent location: the same one across restarts, a different one **per service and per replica**.
{% endhint %}

Unlike the device SDKs, `init` does nothing on its own — no environment burst, no background listeners. It only prepares the send loop. Every event is supplied later, per batch.

## 3. Report a user batch

Each batch is self-contained and tagged with the user it belongs to. See [Report a user batch](https://github.com/Keewano/TypeScript-SDK/blob/main/docs/nodejs.md#3-report-a-user-batch) for the full shape, including how to identify the user and why the build callback must be synchronous.

## 4. Custom events

For events specific to your product beyond the built-in set, see [Custom Events Codegen](https://docs.keewano.com/sdks/custom-events-codegen.md) — use the `node` target.

Note that the `node` target takes the per-batch reporter as the first argument — `reportPlayerRank(reporter, 42)` — because the relay emits inside `reportUserBatch`.

***

## Full documentation

|                                                                                                                                                                                                                                                                                                        |                                                              |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------ |
| [Node.js (Server Relay)](https://github.com/Keewano/TypeScript-SDK/blob/main/docs/nodejs.md)                                                                                                                                                                                                           | The full server guide — batches, identity, offline, shutdown |
| [Configuration](https://github.com/Keewano/TypeScript-SDK/blob/main/docs/configuration.md)                                                                                                                                                                                                             | Every `init` option                                          |
| [Event Types](https://github.com/Keewano/TypeScript-SDK/blob/main/docs/event-types.md)                                                                                                                                                                                                                 | The full map of events                                       |
| [In-App Purchases](https://github.com/Keewano/TypeScript-SDK/blob/main/docs/in-app-purchases.md) · [Subscription Revenue](https://github.com/Keewano/TypeScript-SDK/blob/main/docs/subscription-revenue.md) · [Item Economy](https://github.com/Keewano/TypeScript-SDK/blob/main/docs/item-economy.md) | The event families a server most often reports               |

Package: [`@keewano/node-sdk`](https://www.npmjs.com/package/@keewano/node-sdk) · Source: [github.com/Keewano/TypeScript-SDK](https://github.com/Keewano/TypeScript-SDK)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.keewano.com/sdks/nodejs.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
