Etherpad CLI Client

raw JSON →
3.0.5 verified Thu Apr 23 auth: no javascript

The `etherpad-cli-client` package provides a Node.js and CLI interface for real-time interaction with Etherpad content. It allows developers to connect to an Etherpad instance, stream pad text, listen for real-time messages, and programmatically append or prefix content. The current stable version is 3.0.5. A critical design decision is that this client *requires* the connected Etherpad server to be running in `loadTest` mode, which fundamentally alters Etherpad's behavior and is not suitable for typical production environments. This limits its use to specific testing, automation, or specialized integration scenarios rather than full-fledged editor functionality. The project appears actively maintained, with continuous integration badges indicating ongoing development. Its core differentiator is its programmatic access to real-time Etherpad content, albeit under the `loadTest` mode constraint.

error Error: Client side Etherpad installation needs to be in loadTest mode (settings.json)
cause The Etherpad server you are trying to connect to is not configured with `loadTest: true` in its `settings.json`.
fix
Edit your Etherpad server's settings.json file, add or set "loadTest": true, and restart the Etherpad server.
error TypeError: Client.connect is not a function
cause You are attempting to destructure `connect` directly from the module or calling it incorrectly, rather than as a static method of the imported `Client` class.
fix
Ensure you import the Client class correctly using const Client = require('etherpad-cli-client'); and then call its static method: Client.connect(url);.
error ReferenceError: require is not defined
cause This error occurs in an ECMAScript Module (ESM) context when you try to use `require()` directly.
fix
If your project is configured with "type": "module" in package.json, use import Client from 'etherpad-cli-client'; for CJS interoperability. Alternatively, switch your project to CommonJS by removing "type": "module".
breaking This client requires the connected Etherpad server to be in `loadTest` mode. This is a non-standard configuration and will likely break normal Etherpad operations or prevent other clients from connecting correctly. Ensure `loadTest: true` is set in your Etherpad `settings.json`.
fix Modify your Etherpad server's `settings.json` to include `"loadTest": true` and restart the Etherpad server.
gotcha The package explicitly requires Node.js version 18.0.0 or higher. Running on older Node.js versions may lead to unexpected errors or failures.
fix Upgrade your Node.js environment to version 18.0.0 or later. Use a version manager like `nvm` to easily switch Node.js versions (e.g., `nvm install 18 && nvm use 18`).
gotcha The client offers limited functionality, primarily focusing on streaming, appending, and listening to pad content. It does not provide full editor feature parity, such as complex text manipulation, undo/redo, or user management that a standard Etherpad client offers.
fix Understand the scope of this client. If you need full editor capabilities, consider alternative Etherpad API clients or direct browser-based interaction.
gotcha This package is distributed as a CommonJS module. While Node.js 18+ supports ESM, direct `import` statements might require specific configuration (`type: "module"` in `package.json` or dynamic `import()`) or may not behave as expected without proper interop handling.
fix Prefer `const Client = require('etherpad-cli-client');` for importing the module in CommonJS environments. If using in an ESM project, use `import Client from 'etherpad-cli-client';` leveraging Node.js's CJS-ESM interop, but be aware of potential quirks.
npm install etherpad-cli-client
yarn add etherpad-cli-client
pnpm add etherpad-cli-client

Demonstrates connecting to an Etherpad instance, listening for connection status, real-time messages, and updates to the pad's content, while also programmatically appending text. Requires the Etherpad server to be in `loadTest` mode for full functionality.

const Client = require("etherpad-cli-client");

// IMPORTANT: Ensure your Etherpad instance is in loadTest mode (settings.json -> loadTest: true).
// This example connects to a public beta instance that may or may not be in loadTest mode.
const pad = Client.connect("https://beta.etherpad.org/p/clitest");

pad.on("connected", function(padState){
  console.log(`Connected to Etherpad at ${padState.host} with pad ID ${padState.padId}`);
  // Start appending content once connected
  let counter = 0;
  const intervalId = setInterval(() => {
    const textToAppend = `Hello from CLI Client! [${Date.now()}]\n`;
    console.log(`Appending: "${textToAppend.trim()}"`);
    pad.append(textToAppend);
    counter++;
    if (counter >= 3) { // Append a few times then stop
      clearInterval(intervalId);
    }
  }, 2000);
});

pad.on("message", function(message){
  console.log("New message from Etherpad Server:", message.type);
  // You can inspect message.data for specific Etherpad protocol details
});

pad.on("newContents", function(atext){
  console.log("\n--- Pad Contents Updated ---");
  console.log(atext.text);
  console.log("----------------------------\n");
});

pad.on("disconnect", function(e){
  console.log("Disconnected from pad:", e ? e.message : "gracefully");
  process.exit(0);
});

// Keep the process alive for a reasonable duration to observe real-time events
setTimeout(() => {
  console.log("Exiting after 30 seconds to prevent indefinite running.");
  process.exit(0);
}, 30000);