Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/strophe/strophejs/llms.txt

Use this file to discover all available pages before exploring further.

Strophe.js is published to npm as strophe.js and ships a single package with multiple distribution formats — an ES module bundle, a CommonJS bundle, a Node.js-specific ESM build, and a UMD browser bundle. You can install it with any Node.js package manager, load it from a CDN for quick prototyping, or drop the UMD file directly into a <script> tag. The sections below walk through each path.

Install via Package Manager

1

Install the package

Run the install command for your preferred package manager:
npm install strophe.js
2

Install peer dependencies (Node.js only)

When running in Node.js, the browser-native WebSocket and DOM APIs are not available. Strophe.js declares jsdom and ws as optional peer dependencies to fill this gap:
npm install jsdom ws
  • ws — a WebSocket client/server implementation for Node.js, used by the Websocket and WorkerWebsocket transports.
  • jsdom — a full DOM implementation for Node.js, used for XML parsing and stanza construction.
Both packages are optional: if you only target browsers you can skip this step entirely.
3

Import the library

Add the import to your source file. All public exports are available from the top-level strophe.js specifier:
import { Strophe, $build, $msg, $iq, $pres, stx } from 'strophe.js';
See the Import Examples section below for the full list of named exports and the equivalent CommonJS require syntax.

Package Entry Points

The package.json defines separate entry points so bundlers and runtimes automatically receive the right format:
FieldFileUsed by
moduledist/strophe.esm.jsBrowser ESM bundlers (Vite, Rollup, webpack)
browser (require)dist/strophe.umd.cjsBrowser CJS bundlers
main (node)dist/strophe.cjsNode.js require()
node (import)dist/strophe.node.esm.jsNode.js import
unpkg / CDNdist/strophe.umd.min.js<script> tags, CDN
typesdist/types/index.d.tsTypeScript compiler
You never need to reference these paths directly — the exports map in package.json routes import/require calls to the correct file based on the environment automatically.

Import Examples

Modern bundlers targeting browsers resolve the module entry point. Import the named exports you need:
import { Strophe, $build, $msg, $iq, $pres, stx } from 'strophe.js';

const conn = new Strophe.Connection('wss://chat.example.com/websocket');
All of $build, $msg, $iq, $pres, Strophe, and stx are also registered on globalThis by the library, so they are available as globals in browser environments without an explicit import.

TypeScript Support

TypeScript type declarations are generated from the source and placed at dist/types/index.d.ts. The types field in package.json points there, so no @types/strophe.js package is needed — types are resolved automatically when you add strophe.js to your project.
import { Strophe, $iq } from 'strophe.js';

const conn = new Strophe.Connection('wss://chat.example.com/websocket', {
  mechanisms: [Strophe.SASLSHA256, Strophe.SASLPlain],
  keepalive: true,
});
Strophe.js v4.1 will complete the migration to full TypeScript source. Type definitions were first introduced in v2.0 via JSDoc annotations and generated type declaration files. If you are on an older version and see missing types, upgrade to v2.0 or later.

Build docs developers (and LLMs) love