---
url: https://talkjs.com/docs/Data_APIs/JavaScript
---

# JavaScript Data API

Ask a question Copy for LLM [View as Markdown](/docs/Data_APIs/JavaScript.md)
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](/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](#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.9.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({ ... });
```