# Server-side work

> Convert, edit, and export documents in Node with revise/server.

`revise/server` is the ESM-only Node 20+ entry point bundled in `revise`. It does not import React, and the browser editor never imports `revise/server`.

```bash
npm i revise
```

`Y.Doc` state is interchangeable between the browser editor and `revise/server`, and both use the same converters, tool schemas, and `{ ok, value | error }` result envelope:

```ts
import { ReviseDocument } from "revise/server";
import type * as Y from "yjs";

async function reviewRoom(room: Y.Doc): Promise<Uint8Array> {
  const doc = await ReviseDocument.fromYDoc(room, { author: "Review bot" });
  try {
    const [hit] = doc.grep("Delaware");
    if (hit) {
      await doc.tools.call("replace", {
        id: hit.id,
        replacements: [{ find: "Delaware", replace: "New York" }],
      });
    }
    const { bytes } = await doc.export({ format: "docx" });
    return bytes;
  } finally {
    doc.dispose(); // leaves room alive
  }
}
```

<CardGroup cols={2}>
  <Card title="Library" icon="code" href="https://revise.io/developer/docs/editor-sdk/api/library">
    Open, read, edit, review, and export documents.
  </Card>
  <Card title="Collaboration" icon="users" href="https://revise.io/developer/docs/editor-sdk/api/server-collaboration">
    Seed, edit, and export live Yjs rooms.
  </Card>
  <Card title="Server editing" icon="server" href="https://revise.io/developer/docs/editor-sdk/guides/collaboration#server-editing">
    Coordinate server and browser peers in one room.
  </Card>
  <Card title="Tools on the server" icon="robot" href="https://revise.io/developer/docs/editor-sdk/guides/agent-tools#server-side-editing">
    Run agent tools headlessly in Node.
  </Card>
  <Card title="Document processing and templates" icon="file-lines" href="https://revise.io/developer/docs/editor-sdk/guides/document-processing">
    Template filling, table updates, version comparison, and conversion.
  </Card>
  <Card title="Production deployment" icon="shield-check" href="https://revise.io/developer/docs/editor-sdk/guides/production-deployment">
    Zero-egress setup, WASM caching, and Node concurrency.
  </Card>
</CardGroup>

## Upgrade from 2.x

4.x replaces the 2.x standalone functions with `ReviseDocument` (legacy names remain exported and throw with migration messages; see the [2.3 reference](https://revise.io/developer/docs/editor-sdk/v2.3/api/backend)):

| 2.x | 4.x |
| --- | --- |
| `createServerDocumentSession(ydoc)` | `ReviseDocument.fromYDoc(ydoc)`, then `doc.tools` |
| `parseDocument`, `documentToDocx`, `fileToYDoc` | `ReviseDocument.open(file)`, `doc.export({ format: "docx" })`, `doc.ydoc` |
| `exportDocument(room, { mode })`, `ydocToDocx(room)` | `ReviseDocument.fromYDoc(room)`, then `doc.export({ format, mode })` |
| `seedYDocFromFile(room, bytes, filename)` | `seedYDoc(room, { bytes, filename })` |
| `encodeYDoc`, `decodeYDoc` | `Y.encodeStateAsUpdate(doc.ydoc)`; `ReviseDocument.restore(update)` |

Porting notes:
- `ReviseDocument` methods are async.
- `doc.tools.call()` (typed) and `doc.tools.run()` (untyped) return `ReviseToolResult` instead of throwing.
- `doc.export()` returns `{ bytes, fidelity, warnings, … }`.
- `doc.snapshot()` uses Revise's own storage format; use `Y.encodeStateAsUpdate(doc.ydoc)` for Yjs transports.

## License

`revise/server` is governed by the [SDK license](https://revise.io/developer/docs/editor-sdk/license), including commercial-use requirements for server-only deployments.
