Registry / messaging / cometd

cometd

JSON →
library9.0.0jsnpmunverified

CometD is a scalable comet and WebSocket messaging library for web applications, providing publish/subscribe, RPC, and peer-to-peer communication patterns. The current stable version is 9.0.0, released under the Apache 2.0 license. It ships TypeScript types and supports ES modules. CometD replaces the older cometd-jQuery and provides a modern, promise-based API. It differentiates from alternatives like Socket.IO by being more lightweight and focusing on the Bayeux protocol with built-in support for long-polling, WebSocket, and extensions like time-stamping.

npm install cometd
INSTALL
IMPORT
SIG · COMETD
C
cometd
messagingjavascriptv9.0.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

CometD
✓ import { CometD } from 'cometd'
✗ const CometD = require('cometd').CometD
CommonJS require is not supported in the ES module distribution. Use named import.
TimeStampExtension
✓ import { TimeStampExtension } from 'cometd/TimeStampExtension'
✗ import TimeStampExtension from 'cometd/TimeStampExtension'
TimeStampExtension is a named export, not default. Use named import syntax.
default import (assuming no default export)
✓ import { CometD } from 'cometd'
✗ import CometD from 'cometd'
There is no default export; always use named imports.

Initializes a CometD client, registers a time-stamp extension, configures the URL, performs a handshake, and subscribes to a topic.

import { CometD } from 'cometd'; import { TimeStampExtension } from 'cometd/TimeStampExtension'; const cometd = new CometD(); cometd.registerExtension('timestamp', new TimeStampExtension()); cometd.configure({ url: process.env.COMETD_URL ?? 'http://localhost:8080/cometd' }); cometd.handshake((reply) => { if (reply.successful) { console.log('Handshake succeeded'); cometd.subscribe('/topic', (message) => { console.log('Received message:', message.data); }); } });
Debug
Known issues
breakingVersion 9 drops support for older browser APIs and requires ES module environment.
fix
Ensure your runtime supports ES modules (Node >=13.2 or modern browser). Use import/export syntax.
affects: >=9.0.0
deprecatedThe cometd-jQuery integration module is deprecated and removed in v9.
fix
Use the core CometD library without jQuery. Migrate any jQuery-specific extensions.
affects: >=9.0.0
breakingCommonJS require() no longer works starting from v8.0.0.
fix
Switch to ES module imports: import { CometD } from 'cometd'.
affects: >=8.0.0
gotchaImport paths for extensions are case-sensitive and must use forward slashes.
fix
Use correct path like 'cometd/TimeStampExtension' not 'cometd/timestamp'.
affects: >=8.0.0
Errors
Common errors & fixes
Uncaught TypeError: cometd.configure is not a function
CometD object not properly imported (default import used instead of named import).
fix
Use named import: import { CometD } from 'cometd';
Cannot find module 'cometd'
Package not installed or import path incorrect in CommonJS environment.
fix
Install package via npm install cometd and ensure using ES module syntax.
Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of ...
Server misconfigured to serve .js files with incorrect MIME type for ES modules.
fix
Configure server to serve .js files with MIME type application/javascript or text/javascript.
Upgrade
Version history
9.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
29 hits · last 30 days
node
28
OpenAI (training)
1
Resources
packagecometd ↗
cometd — npm install cometd · libregistry