![NodeJS CI](https://github.com/cometd/cometd-nodejs-client/workflows/NodeJS%20CI/badge.svg)

## The CometD Project

### CometD NodeJS Client

This project implements ES6 adapter code that allows the [CometD JavaScript Client](https://github.com/cometd/cometd-javascript) to run in NodeJS 18.x or greater.

The adapter code exports an implementation of `XMLHttpRequest` and `WebSocket` so that the CometD JavaScript Client works in NodeJS as it does within a browser environment.

WebSocket is supported via the [`ws`](https://www.npmjs.com/package/ws) package.

### NPM Installation

Install the CometD NodeJS Client:

```js
npm install cometd-nodejs-client
```

### Usage (ES6)

```js
import { adapt } from "cometd-nodejs-client";
import { CometD } from "cometd";

// Shim XMLHTTPRequest for Node.js (required by CometD).
adapt();

// Your normal CometD client application here.
const client = new CometD();
```

See [here](https://github.com/cometd/cometd-javascript/blob/master/README.md) for an example CometD client application.
