---
url: https://talkjs.com/docs/Data_APIs/JavaScript/
title: "JavaScript Data API | TalkJS Docs"
---

For AI agents: Find a documentation index at https://talkjs.com/llms.txt (full content at https://talkjs.com/llms-full.txt). Get a markdown version of any page by appending .md to its URL path.

# JavaScript Data API

Connect to chat data as a user.

The JavaScript Data API lets you connect to your TalkJS chat as a user and read, subscribe to, and update your chat data. It's available as an npm package, [`@talkjs/core`](https://www.npmjs.com/package/@talkjs/core), and as part of the [Classic JavaScript SDK](https://talkjs.com/docs/UI_Components/JavaScript/Classic/). It supports the following platforms:

-   Browsers
-   React Native
-   Node.js

The Data API is primarily intended to be used in the client environments, such as browsers or React Native, because it connects as a single specific user. However, you can also use it in Node.js. See [Node.js compatibility](https://talkjs.com/docs/Data_APIs/JavaScript/#nodejs-compatibility) for more details.

## How to install TalkJS Core

You can install the [`@talkjs/core` NPM package](https://www.npmjs.com/package/@talkjs/core), or include it as a script.

### Install with a package manager

Install the `@talkjs/core` npm package:

**npm**

```shell
npm install @talkjs/core
```

**yarn**

```shell
yarn add @talkjs/core
```

### Include as a script

If you use TalkJS without a build step, you can include TalkJS core as a script.

Add the following to the `<head>` tag of the HTML page where you want to use TalkJS Core:

```html
<script type="module">
  import { getTalkSession } from 'https://cdn.jsdelivr.net/npm/@talkjs/core@1.12.1';
</script>
```

## Node.js compatibility

If you use TalkJS Core in Node.js version 22, it will use the built-in WebSocket implementation automatically. Node.js version 21 will also use the built-in implementation if the `--experimental-websocket` flag is enabled.

If you are using an older version of Node.js without built-in support for WebSockets, you will need to add support with a library. We recommend installing the `ws` package. Then tell `@talkjs/core` to use `WebSocket` from `ws`:

```js
import { getTalkSession, registerPolyfills } from "@talkjs/core";
import { WebSocket } from "ws";

registerPolyfills({ WebSocket: WebSocket });

const session = getTalkSession({ ... });
```
