Etherpad CLI Client
raw JSON →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.
Common errors
error Error: Client side Etherpad installation needs to be in loadTest mode (settings.json) ↓
settings.json file, add or set "loadTest": true, and restart the Etherpad server. error TypeError: Client.connect is not a function ↓
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 ↓
"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". Warnings
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`. ↓
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. ↓
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. ↓
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. ↓
Install
npm install etherpad-cli-client yarn add etherpad-cli-client pnpm add etherpad-cli-client Imports
- Client wrong
import Client from 'etherpad-cli-client';correctconst Client = require('etherpad-cli-client'); - connect wrong
const { connect } = require('etherpad-cli-client');correctconst Client = require('etherpad-cli-client'); const pad = Client.connect('https://beta.etherpad.org/p/clitest'); - pad instance methods wrong
const pad = require('etherpad-cli-client').connect();correctconst Client = require('etherpad-cli-client'); const pad = Client.connect(); pad.on('connected', () => { /* ... */ }); pad.append('new content');
Quickstart
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);