--- title: Introduction project: OpenSync version: 1.0 section: guides language: en license: MIT url: https://totaljs.es/docs/opensync/1-0/guides/introduction/ updated: 2026-11-19T09:22:08.629Z --- # Introduction > What OpenSync is, how it works and where to start. OpenSync is a small synchronization server. Your apps and services send data to it over HTTP, on named **channels** such as `orders` or `stock`. OpenSync turns every request into a JSON message and sends it at once to all the clients that listen on that channel, over WebSocket or Server-Sent Events. OpenSync is an official Total.js app under the MIT license. The code is on [GitHub](https://github.com/totaljs/opensync). ## What you can do - Send data to a channel with any HTTP method: `GET`, `POST`, `PUT`, `PATCH` or `DELETE`, as JSON, form data, plain text or files. - Receive the data live in your apps, web pages and scripts, over WebSocket or Server-Sent Events. - Send messages from one WebSocket client to all the others. - Give each app its own **access token**, and limit which channels it receives. - See the connected apps on the **Clients** page. - Keep a log of every request. - Receive webhooks, for example from Slack, with an extension. ## How it fits together 1. Your shop sends `POST /sync/orders/` with the new order as JSON. 2. OpenSync answers `200` with an empty body. 3. Every client connected with a token that can read `orders` gets a message with the channel, the method, the headers, the query and the body of that request. ## Where to go next - Install OpenSync [from source](../install-source/) or [with Docker](../install-docker/). - Save the [first setup](../first-setup/) and create [access tokens](../access-tokens/). - Connect a client: [WebSocket](../../reference/websocket/) or [Server-Sent Events](../../reference/server-sent-events/). - Send data: [Send data over HTTP](../../reference/send-http/). --- title: Install from source project: OpenSync version: 1.0 section: guides language: en license: MIT url: https://totaljs.es/docs/opensync/1-0/guides/install-source/ updated: 2026-11-19T09:22:08.629Z --- # Install from source > Install OpenSync with Node.js and start it on your computer or server. You need [Node.js](https://nodejs.org) and Git. ## Install and start **1.** Get the code and open its folder: ```bash git clone https://github.com/totaljs/opensync.git cd opensync ``` **2.** Install the dependencies (once): ```bash npm install ``` **3.** Start OpenSync: ```bash npm start ``` **4.** Open `http://localhost:8000/` in your browser. On a new instance it opens the setup page. See [First setup](../first-setup/). OpenSync keeps running until you stop it with Ctrl+C in the terminal. ## Use another port `npm start` uses port 8000. To use another port, start OpenSync with Node.js and pass the port: ```bash node index.js 8080 ``` ## Where your data is saved The settings, the access tokens, the extensions and the request log are saved in the `databases` folder inside the OpenSync folder. See [The data folder](../../reference/data-folder/). Before you open OpenSync to other people, read [Run in production](../production/). --- title: Install with Docker project: OpenSync version: 1.0 section: guides language: en license: MIT url: https://totaljs.es/docs/opensync/1-0/guides/install-docker/ updated: 2026-11-19T09:22:08.629Z --- # Install with Docker > Build the OpenSync image from the repository and run it with a volume for your data. The repository has a `Dockerfile`. You build the image yourself and run it with a volume, so your setup survives when you recreate the container. ## Build and run **1.** Get the code and open its folder: ```bash git clone https://github.com/totaljs/opensync.git cd opensync ``` **2.** Build the image: ```bash docker build -t opensync . ``` **3.** Start a container. OpenSync listens on port 8000 inside the container, and the volume `opensync-data` keeps the data: ```bash docker run -d --name opensync -p 8000:8000 -v opensync-data:/www/.src/databases opensync ``` **4.** Open `http://localhost:8000/`. On a new instance it opens the setup page. See [First setup](../first-setup/). ## Where the data lives Inside the container OpenSync runs from `/www/.src/`, and the data is in `/www/.src/databases/`. That folder is the `opensync-data` volume. When you remove the container and start a new one with the same volume, your name, tokens and settings are still there. To see what is in the data folder: ```bash docker exec opensync ls /www/.src/databases ``` The image runs OpenSync from its bundle file, so the instance menu has **Update bundle**. See [Update the bundle](../update-bundle/). The image has no extensions; add the ones you need on the [Extensions](../extensions/) page. ## Stop and start ```bash docker stop opensync docker start opensync ``` Before you open OpenSync to other people, read [Run in production](../production/). --- title: First setup project: OpenSync version: 1.0 section: guides language: en license: MIT url: https://totaljs.es/docs/opensync/1-0/guides/first-setup/ updated: 2026-11-19T09:22:08.629Z --- # First setup > Name your instance, keep the setup token and save the first setup. A new OpenSync instance has no setup token yet. Until you save the first setup, the home page redirects to the setup page and anyone who opens it can choose the setup token. Save the first setup right after you start OpenSync.  ## Save the first setup 1. Open `http://localhost:8000/`. OpenSync redirects to `/setup/`. 2. In **Name**, type a name for this instance, for example `Demo sync`. Clients receive this name when they connect. 3. Leave **Storage path** as `/databases/`. The path cannot be changed after the first setup. 4. **Setup token** is already filled with a new random token. Keep it, or click **Generate token** for another one. 5. Click **APPLY**. The page shows **Setup has been saved succesfully**, and the address in your browser now ends with `?token=` and your setup token. Bookmark that address or save the token in your password manager: it is the only way into the setup interface. ## What the setup token does - It opens the setup interface. See [The setup interface](../setup-interface/). - It also works as a client token that receives every channel. For your apps, create separate [access tokens](../access-tokens/) instead. ## Next steps - Create an [access token](../access-tokens/) for each app. - Connect a client: [WebSocket](../../reference/websocket/) or [Server-Sent Events](../../reference/server-sent-events/). --- title: The setup interface project: OpenSync version: 1.0 section: guides language: en license: MIT url: https://totaljs.es/docs/opensync/1-0/guides/setup-interface/ updated: 2026-11-19T09:22:09.965Z --- # The setup interface > Open the setup interface with your setup token, find your way around and sign out. The setup interface is where you manage your OpenSync instance. It has three pages in the menu on the left: **Setup**, **Clients** and **Extensions**.  ## Open it Open `/setup/` with your setup token in the `token` query argument: ```text https://sync.example.com/setup/?token=YOUR_SETUP_TOKEN ``` Without the token, or with a wrong one, OpenSync answers `401`. After several wrong tokens from the same IP address, OpenSync refuses that address for a while. See [Access problems](../../faq/access/). ## The pages - **Setup**: the instance name, the setup token, [Log all requests](../request-log/), [Disconnect the setup interface](../disconnect-setup/) and the [access tokens](../access-tokens/). Changes take effect when you click **APPLY**. - **Clients**: the apps connected over WebSocket. See [Connected clients](../clients/). - **Extensions**: the installed extensions. See [Extensions](../extensions/). The top left corner shows `OpenSync v1` and how much memory OpenSync uses. ## Change the setup token 1. On the **Setup** page, click **Generate token** under **Setup token**, or type your own token. 2. Click **APPLY**. The browser reloads the page with the new token in the address. The old setup token stops working at once. ## Sign out Click **OpenSync v1** in the top left corner and choose **Logout**. The browser goes to the home page of OpenSync, which only shows `OpenSync v1`. To come back, open `/setup/?token=` with your setup token again.  **Update bundle** appears only when OpenSync runs from a bundle file, as in the Docker image. See [Update the bundle](../update-bundle/). --- title: Access tokens project: OpenSync version: 1.0 section: guides language: en license: MIT url: https://totaljs.es/docs/opensync/1-0/guides/access-tokens/ updated: 2026-11-19T09:22:07.357Z --- # Access tokens > Create, edit, copy and remove the tokens your apps use to connect. Every client that connects to OpenSync needs a token. Create one **access token** for each app, so you can see who is connected and remove one app without touching the others.  ## Create a token 1. On the **Setup** page, click **Add** next to **Access tokens**. 2. In **Name**, type the name of the app, for example `Demo app`. 3. Leave **Allow to use only these channels** empty to receive every channel, or add channels. See [Limit a token to channels](../token-channels/). 4. Click **SUBMIT**. 5. Click **APPLY** at the bottom of the page. The token is saved only when you click **APPLY**. OpenSync creates the token value for you.  ## Copy a token Click the **...** button of a token: - **Copy URL address** copies the address a client connects to, with the token: `https://sync.example.com/?token=…`. - **Show token** shows the token in the list. - **Copy token** copies only the token.  Use the token in the `token` query argument of the [WebSocket](../../reference/websocket/) or [Server-Sent Events](../../reference/server-sent-events/) address. ## Edit a token Click a token, or choose **Edit** in its **...** menu. Change the name or the channels, click **SUBMIT** and then **APPLY**. Connected clients get the new channels at once; they do not need to reconnect. ## Remove a token Choose **Remove** in the **...** menu and click **APPLY**. Clients connected with that token are disconnected at once (WebSocket close code `4001`), and the token cannot connect again. --- title: Limit a token to channels project: OpenSync version: 1.0 section: guides language: en license: MIT url: https://totaljs.es/docs/opensync/1-0/guides/token-channels/ updated: 2026-11-19T09:22:09.965Z --- # Limit a token to channels > Choose which channels the clients of an access token receive. By default an access token receives the messages of **all channels**. You can limit it to a list of channels, for example a warehouse app that needs only `orders`. ## Set the channels 1. On the **Setup** page, click the token (or choose **Edit** in its **...** menu). 2. Click **Allow to use only these channels**, type a channel name and press Enter. Repeat for each channel. 3. To remove a channel, click the **×** on its tag. 4. Click **SUBMIT**, then **APPLY**. The list shows the channels under the token name. A token without channels shows **all channels**. ## What changes A client connected with the token receives only the messages of the listed channels. Messages of other channels are not sent to it. For example, with these two tokens: | Token | Channels | Receives `orders` | Receives `stock` | |---|---|---|---| | Demo app | all channels | yes | yes | | Orders app | `orders` | yes | no | The change applies to connected clients as soon as you click **APPLY**. --- title: Log all requests project: OpenSync version: 1.0 section: guides language: en license: MIT url: https://totaljs.es/docs/opensync/1-0/guides/request-log/ updated: 2026-11-19T09:22:08.629Z --- # Log all requests > Keep a file with every message that goes through OpenSync. With **Log all requests** on, OpenSync writes every message to the file `audit.log` in the [data folder](../../reference/data-folder/). The log holds the messages from HTTP requests and from WebSocket clients, also when no client is connected. ## Turn it on 1. On the **Setup** page, check **Log all requests**. 2. Click **APPLY**. To stop logging, uncheck it and click **APPLY**. ## What the log looks like Each line is one message as JSON, with an extra `dtcreated` field (the time the message was logged): ```json {"id":"24nag001tl51d","type":"application/json","channel":"orders","method":"POST","headers":{"host":"sync.example.com","user-agent":"curl/8.7.1","accept":"*/*","content-type":"application/json","content-length":"11"},"ua":"","query":{},"body":{"id":1004},"ts":"2026-11-19T07:40:29.624Z","ip":"203.0.113.10","files":[],"dtcreated":"2026-11-19T07:40:29.624Z"} ``` The fields are described in [Message format](../../reference/message-format/). While the log is on, clients also receive `dtcreated` in their messages. ## Read the log Show the last messages: ```bash tail -n 20 databases/audit.log ``` The file grows with every message. Keep an eye on its size, and include it in your backups if you need the history. --- title: Disconnect the setup interface project: OpenSync version: 1.0 section: guides language: en license: MIT url: https://totaljs.es/docs/opensync/1-0/guides/disconnect-setup/ updated: 2026-11-19T09:22:07.710Z --- # Disconnect the setup interface > Lock the setup interface for everyone, and open it again from the data folder. When your instance is ready, you can lock the setup interface. Nobody can then open it, not even with the setup token. OpenSync keeps working with the access tokens you created. ## Disconnect it 1. On the **Setup** page, check **Disconnect the setup interface**. The **Setup token** field disappears. 2. Click **APPLY**. From now on: - `/setup/` answers `401` for every token. - The setup token cannot connect as a client. - The [access tokens](../access-tokens/) keep working. ## Open it again You need access to the server and the [data folder](../../reference/data-folder/). **1.** Stop OpenSync. **2.** Open `databases/preferences.json` in a text editor and change `disconnected` to `false`: ```json "disconnected": false ``` **3.** Start OpenSync and open `/setup/?token=` with your setup token. The setup token is the `token` value in the same file. --- title: Connected clients project: OpenSync version: 1.0 section: guides language: en license: MIT url: https://totaljs.es/docs/opensync/1-0/guides/clients/ updated: 2026-11-19T09:22:07.710Z --- # Connected clients > See which apps are connected to OpenSync over WebSocket. The **Clients** page lists the clients connected over WebSocket. It refreshes every 30 seconds.  For each client you see: | Field | Meaning | |---|---| | IP address | The address the client connects from, at the top of the card. | | **App name** | The `app` query argument of the connection, or `---` when the client sent none. | | **Access token** | The name of the [access token](../access-tokens/) it uses. | | **Latency** | The latency of the connection. | | **Connected** | When it connected. | Give each app a name in its connection address, so you can tell them apart: ```text wss://sync.example.com/?token=YOUR_TOKEN&app=Dashboard ``` Clients that listen with [Server-Sent Events](../../reference/server-sent-events/) receive messages too, but they are not listed here. --- title: Extensions project: OpenSync version: 1.0 section: guides language: en license: MIT url: https://totaljs.es/docs/opensync/1-0/guides/extensions/ updated: 2026-11-19T09:22:08.225Z --- # Extensions > Add, download and remove extensions, such as the Slack extension. Extensions add features to OpenSync. Each extension is one JavaScript file. The **Extensions** page lists the installed ones.  ## The Slack extension The source code of OpenSync comes with the **Slack** extension (in `databases/extensions/slack.js`). It lets Slack send its events to OpenSync. See [Receive Slack events](../../recipes/slack-events/). The Docker image has no extensions. To use the Slack extension there, add the file `databases/extensions/slack.js` of the repository with **Add**. ## Add an extension 1. Click **Add** at the top right. 2. Choose the extension's `.js` file. OpenSync shows **The extension has been added successfully**, and the extension works at once. Its file is saved in `databases/extensions/`. Add only extensions from sources you trust: an extension runs inside OpenSync with full access to it. ## Download or remove an extension Click the **...** button of an extension: - **Download** saves the extension's file, for example `slack.js`. - **Remove** removes the extension after you confirm. Its feature stops at once. --- title: Update the bundle project: OpenSync version: 1.0 section: guides language: en license: MIT url: https://totaljs.es/docs/opensync/1-0/guides/update-bundle/ updated: 2026-11-19T09:22:09.965Z --- # Update the bundle > Replace the app.bundle file of a bundled OpenSync from the setup interface. The Docker image runs OpenSync from one file, `app.bundle`. You can replace that file from the setup interface, without rebuilding the image. The repository has the current `app.bundle` in its root folder. **Update bundle** is only in the menu when OpenSync runs from a bundle. A source install updates with Git instead (see below). ## Upload a new bundle 1. Get the new `app.bundle` file. 2. In the setup interface, click **OpenSync v1** in the top left corner and choose **Update bundle**. 3. Confirm, and choose the `app.bundle` file. OpenSync saves the file and restarts after about one second. The page reloads after a few seconds. Your setup, tokens and extensions stay as they are. A file that does not end with `.bundle` is refused with **Invalid file**. ## Update a source install In the OpenSync folder: ```bash git pull npm install ``` Then restart OpenSync. --- title: Run in production project: OpenSync version: 1.0 section: guides language: en license: MIT url: https://totaljs.es/docs/opensync/1-0/guides/production/ updated: 2026-11-19T09:22:08.629Z --- # Run in production > Start OpenSync in release mode and keep it safe on a public server. `npm start` runs OpenSync in debug mode. On a server, start it in release mode. ## Start in release mode ```bash node index.js 8000 --release ``` The start log then shows `release` as the `Mode`. Keep OpenSync running with the process manager you use for your other Node.js apps, or run the [Docker image](../install-docker/). ## Keep it safe - **Save the first setup at once.** Until the first setup is saved, anyone who opens the address can set the setup token. See [First setup](../first-setup/). - **Use HTTPS.** Tokens travel in the address. Put OpenSync behind a web server with HTTPS, and let clients connect with `wss://` and `https://`. - **Decide who can send.** `/sync/{channel}/` takes requests without a token, so anyone who can reach it can send messages to your clients. Let only your apps and the services you trust reach it, for example with a firewall or rules in your web server. - **Give each app its own token,** limited to the channels it needs. See [Access tokens](../access-tokens/) and [Limit a token to channels](../token-channels/). - **Lock the setup interface** when you do not need it: [Disconnect the setup interface](../disconnect-setup/). - **Back up the data folder.** See [The data folder](../../reference/data-folder/). --- title: Send data over HTTP project: OpenSync version: 1.0 section: reference language: en license: MIT url: https://totaljs.es/docs/opensync/1-0/reference/send-http/ updated: 2026-11-19T09:22:09.965Z --- # Send data over HTTP > Send a request to /sync/{channel}/ to deliver its data to the clients of that channel. ```text GET /sync/{channel}/ POST /sync/{channel}/ PUT /sync/{channel}/ PATCH /sync/{channel}/ DELETE /sync/{channel}/ ``` Send any of these requests, and OpenSync delivers it as a [message](../message-format/) to every client that can read `{channel}`. Pick any channel name, for example `orders`, `stock` or `Orders-EU_2`; channels do not need to be created first. OpenSync answers `200` with an empty body, also when no client is connected. Sending needs no token. See [Run in production](../../guides/production/) to decide who can reach this address. ## JSON ```bash curl -X POST -H "Content-Type: application/json" -d '{"id":1002,"status":"paid"}' "https://sync.example.com/sync/orders/" ``` The clients receive the JSON as an object in `body`: ```json {"id":"24nb4004pu50d","type":"application/json","channel":"orders","method":"POST","headers":{"host":"sync.example.com","user-agent":"curl/8.7.1","accept":"*/*","content-type":"application/json","content-length":"27"},"ua":"","query":{},"body":{"id":1002,"status":"paid"},"ts":"2026-11-19T08:04:51.361Z","ip":"203.0.113.10","files":[]} ``` ## Form data ```bash curl -X PUT -H "Content-Type: application/x-www-form-urlencoded" -d "sku=A-100&qty=7" "https://sync.example.com/sync/stock/" ``` The fields arrive as an object of strings: `"body":{"sku":"A-100","qty":"7"}`. ## Plain text and other types Any other content type arrives as text. A `PATCH` with `Content-Type: text/plain` and the body `hello` arrives as `"type":"text/plain"` and `"body":"hello"`. ## Query arguments only ```bash curl "https://sync.example.com/sync/orders/?id=1001&status=paid" curl -X DELETE "https://sync.example.com/sync/orders/?id=1001" ``` The arguments arrive in `query`, for example `"query":{"id":"1001","status":"paid"}`, and `body` is an empty string. ## Files Send files as `multipart/form-data` with `POST` or `PUT`. See [Send files](../files/). ## Requests that are not delivered | Request | Answer | |---|---| | Another method, for example `OPTIONS` | `404` | | A deeper path, for example `/sync/a/b/` | `404` | | A file upload larger than about 2 MB | `431` | See [Status codes and limits](../status-codes/). --- title: WebSocket project: OpenSync version: 1.0 section: reference language: en license: MIT url: https://totaljs.es/docs/opensync/1-0/reference/websocket/ updated: 2026-11-19T09:22:09.965Z --- # WebSocket > Connect over WebSocket to receive messages, and send messages to a channel. A WebSocket client both receives messages and can send them. All messages are JSON text. ## Connect ```text wss://sync.example.com/?token=YOUR_TOKEN&app=Dashboard ``` | Query argument | Meaning | |---|---| | `token` | An [access token](../../guides/access-tokens/), or the setup token. | | `app` | Optional. The name shown on the [Clients](../../guides/clients/) page. | Use `ws://` when OpenSync runs without HTTPS, for example `ws://localhost:8000/?token=YOUR_TOKEN`. Right after the connection opens, OpenSync sends an `init` message: ```json {"type":"init","name":"Demo sync","version":1,"id":"OpenSync"} ``` `name` is the instance name from the **Setup** page. OpenSync sends `init` again to every connected client when someone clicks **APPLY** on the **Setup** page. ## Receive messages Every request to a channel that the token can read arrives as one [message](../message-format/): ```json {"id":"24nad002tl50d","type":"application/json","channel":"orders","method":"POST","headers":{"host":"sync.example.com","connection":"keep-alive","content-type":"application/json","accept":"*/*","accept-language":"*","sec-fetch-mode":"cors","user-agent":"node","accept-encoding":"gzip, deflate","content-length":"24"},"ua":"","query":{},"body":{"id":1002,"total":49.9},"ts":"2026-11-19T07:37:50.820Z","ip":"203.0.113.10","files":[]} ``` Tell `init` apart from the other messages by `"type":"init"`. ## Send a message Send a `notify` message with the channel and your data in `body`: ```json {"type":"notify","channel":"chat","body":{"text":"Hello"}} ``` Every client that can read `chat` receives it, the sender included: ```json {"id":"24nad007tl51d","type":"application/json","channel":"chat","method":"SOCKET","headers":{},"ua":"","query":{},"body":{"text":"Hello"},"ts":"2026-11-19T07:37:52.847Z","ip":"203.0.113.10","files":[]} ``` `method` is `SOCKET`, and `headers` and `query` are empty. You can name the data field `data` instead of `body`. Messages without a `channel`, or that are not JSON, are ignored. ## When the connection closes | Close code | Reason | |---|---| | `4001` | The token is wrong, was removed, or your IP address is locked after failed attempts. See [Access problems](../../faq/access/). | OpenSync does not keep messages for clients that are offline. Reconnect after a close; see [Listen from Node.js](../../recipes/nodejs-client/). --- title: Server-Sent Events project: OpenSync version: 1.0 section: reference language: en license: MIT url: https://totaljs.es/docs/opensync/1-0/reference/server-sent-events/ updated: 2026-11-19T09:22:09.965Z --- # Server-Sent Events > Receive messages as a Server-Sent Events stream, for scripts and command-line tools. Server-Sent Events is a one-way stream: the client only receives. Use it when your tool cannot speak WebSocket. ## Connect Send `GET /` with the header `Accept: text/event-stream` and your token, in the `token` query argument or the `x-token` header: ```bash curl -N -H "Accept: text/event-stream" -H "x-token: YOUR_TOKEN" "https://sync.example.com/" ``` The stream starts with the `init` message and a retry time, then one `data:` line for each message: ```text data: {"type":"init","name":"Demo sync","version":1,"id":"OpenSync"} retry: 3000 data: {"id":"24nb4004pu50d","type":"application/json","channel":"orders","method":"POST","headers":{"host":"sync.example.com","user-agent":"curl/8.7.1","accept":"*/*","content-type":"application/json","content-length":"27"},"ua":"","query":{},"body":{"id":1002,"status":"paid"},"ts":"2026-11-19T08:04:51.361Z","ip":"203.0.113.10","files":[]} ``` Each `data:` line holds one [message](../message-format/). The token's [channels](../../guides/token-channels/) apply, as with WebSocket. ## Wrong token With a wrong token OpenSync does not open a stream. It answers `200` with the plain text `OpenSync v1`. Failed attempts count toward the lock described in [Access problems](../../faq/access/). ## In a browser Browsers block an `EventSource` to OpenSync from a page on another address, because OpenSync does not send CORS headers. In web pages, use [WebSocket](../websocket/) instead. See [Listen in a web page](../../recipes/web-page/). Clients connected with Server-Sent Events are not listed on the [Clients](../../guides/clients/) page. --- title: Message format project: OpenSync version: 1.0 section: reference language: en license: MIT url: https://totaljs.es/docs/opensync/1-0/reference/message-format/ updated: 2026-11-19T09:22:09.965Z --- # Message format > The fields of the messages that OpenSync sends to clients. Every request to `/sync/{channel}/` and every WebSocket `notify` becomes one JSON message. Clients get the same message over [WebSocket](../websocket/) and [Server-Sent Events](../server-sent-events/). ## Example ```json {"id":"24nb4004pu50d","type":"application/json","channel":"orders","method":"POST","headers":{"host":"sync.example.com","user-agent":"curl/8.7.1","accept":"*/*","content-type":"application/json","content-length":"27"},"ua":"","query":{},"body":{"id":1002,"status":"paid"},"ts":"2026-11-19T08:04:51.361Z","ip":"203.0.113.10","files":[]} ``` ## Fields | Field | Type | Meaning | |---|---|---| | `id` | string | A unique ID of the message. | | `type` | string | The content type of the request, without parameters such as `boundary`: `application/json`, `application/x-www-form-urlencoded`, `multipart/form-data`, `text/plain`… Empty for a request without a body. Always `application/json` for a WebSocket message. | | `channel` | string | The channel. | | `method` | string | `GET`, `POST`, `PUT`, `PATCH`, `DELETE`, or `SOCKET` for a WebSocket message. | | `headers` | object | The request headers, with lower-case names. Empty for a WebSocket message. | | `ua` | string | A short form of the browser and system from the `User-Agent` header, for example `Mac Chrome`. Empty for scripts and tools such as curl. | | `query` | object | The query arguments, as strings. | | `body` | object or string | JSON and form data as an object, other content as text, an empty string without a body. | | `ts` | string | The time OpenSync received the request (ISO 8601, UTC). | | `ip` | string | The IP address of the sender. | | `files` | array | The uploaded files. See [Send files](../files/). | | `dtcreated` | string | Only while [Log all requests](../../guides/request-log/) is on: the time the message was logged. | ## The init message When a client connects, it first gets: ```json {"type":"init","name":"Demo sync","version":1,"id":"OpenSync"} ``` | Field | Meaning | |---|---| | `type` | Always `init`. | | `name` | The instance name from the **Setup** page. | | `version` | The OpenSync version number, `1`. | | `id` | Always `OpenSync`. | --- title: Send files project: OpenSync version: 1.0 section: reference language: en license: MIT url: https://totaljs.es/docs/opensync/1-0/reference/files/ updated: 2026-11-19T09:22:09.965Z --- # Send files > Upload files to a channel and download them from the link in the message. Send files as `multipart/form-data` with `POST` or `PUT` to `/sync/{channel}/`. A request can be up to about 2 MB. ## Upload ```bash curl -F "file=@invoice.txt" "https://sync.example.com/sync/invoices/" ``` OpenSync answers `200` with an empty body. The clients get a message with `"type":"multipart/form-data"` and one entry in `files` for each file: ```json {"id":"24nb4005pu51d","type":"multipart/form-data","channel":"invoices","method":"POST","headers":{"host":"sync.example.com","user-agent":"curl/8.7.1","accept":"*/*","content-length":"230","content-type":"multipart/form-data; boundary=------------------------XS4ofo3RtD8jr9XpifhgO5"},"ua":"","query":{},"body":"","ts":"2026-11-19T08:04:51.696Z","ip":"203.0.113.10","files":[{"name":"file","filename":"invoice.txt","extension":"txt","type":"text/plain","size":29,"width":0,"height":0,"url":"https://sync.example.com/download/wzsufi.dat"}]} ``` ## File fields | Field | Meaning | |---|---| | `name` | The name of the form field, here `file`. | | `filename` | The original file name. | | `extension` | The file extension. | | `type` | The content type of the file. | | `size` | The size in bytes. | | `width`, `height` | The size of an image in pixels, `0` for other files. | | `url` | The download link. It starts with the address the sender used to reach OpenSync. | ## Download Open the `url`, or fetch it: ```bash curl -o invoice.txt "https://sync.example.com/download/wzsufi.dat" ``` The file comes back as a download with its original name (`Content-Disposition: attachment`). The link needs no token. Download the file as soon as your client gets the message. Links are temporary: they stop working when OpenSync restarts, and an unknown link answers `404`. ## Too large A file upload larger than about 2 MB is refused with `431`, and no message is sent. To share larger files, store them somewhere else and send their address in a JSON message. --- title: Status codes and limits project: OpenSync version: 1.0 section: reference language: en license: MIT url: https://totaljs.es/docs/opensync/1-0/reference/status-codes/ updated: 2026-11-19T09:22:09.965Z --- # Status codes and limits > The answers of OpenSync, the WebSocket close codes and the limits. ## HTTP answers | Request | Answer | |---|---| | `GET`, `POST`, `PUT`, `PATCH` or `DELETE` to `/sync/{channel}/` | `200`, empty body. | | Another method, or a deeper path such as `/sync/a/b/` | `404` | | A file upload larger than about 2 MB | `431` | | `/download/{id}.dat` that is unknown or expired | `404` | | `/setup/` without the setup token or with a wrong one | `401` | | `GET /` without a stream request | `200`, plain text `OpenSync v1` (a new instance redirects to `/setup/`). | ## WebSocket | Close code | Reason | |---|---| | `4001` | Wrong or removed token, or the IP address is locked. | ## Locked IP address After six requests with a wrong token from one IP address, OpenSync refuses every request from that address that needs a token, even with the right token. This covers the setup interface and new client connections. The lock ends within 15 minutes, or when OpenSync restarts. See [Access problems](../../faq/access/). ## Limits | What | Limit | |---|---| | File upload | about 2 MB per request | | Messages for offline clients | not kept | | Download links | until OpenSync restarts | --- title: The data folder project: OpenSync version: 1.0 section: reference language: en license: MIT url: https://totaljs.es/docs/opensync/1-0/reference/data-folder/ updated: 2026-11-19T09:22:09.965Z --- # The data folder > What OpenSync saves in its databases folder, and how to back it up. OpenSync keeps everything it saves in the `databases` folder: inside the OpenSync folder for a source install, and in `/www/.src/databases/` in the [Docker image](../../guides/install-docker/). | File | What it holds | |---|---| | `preferences.json` | The instance name, the setup token, the access tokens and the settings of the **Setup** page. | | `extensions/` | The files of the installed [extensions](../../guides/extensions/). | | `extensions.json` | The settings of the extensions. | | `audit.log` | The [request log](../../guides/request-log/), when it is on. | | `memorize_stats.json` | How many messages each token received. | Messages are not stored: OpenSync sends them to the connected clients and keeps nothing else, unless the request log is on. ## Back up Copy the whole folder while OpenSync is stopped, for example: ```bash tar -czf opensync-backup.tar.gz databases ``` For Docker, copy it out of the container: ```bash docker cp opensync:/www/.src/databases ./opensync-backup ``` To restore, stop OpenSync, put the folder back and start OpenSync. `preferences.json` holds your tokens. Keep backups where only you can read them. --- title: Listen from Node.js project: OpenSync version: 1.0 section: recipes language: en license: MIT url: https://totaljs.es/docs/opensync/1-0/recipes/nodejs-client/ updated: 2026-11-19T09:22:09.965Z --- # Listen from Node.js > A small Node.js script that receives the messages and reconnects when the connection drops. Node.js 22 and later have a built-in `WebSocket`, so this script needs no packages. ## The script Save it as `listen.js`, with your address and token: ```js const URL = 'wss://sync.example.com/?token=YOUR_TOKEN&app=Warehouse'; function connect() { const ws = new WebSocket(URL); ws.onmessage = function(e) { const msg = JSON.parse(e.data); if (msg.type === 'init') { console.log('Connected to', msg.name); return; } console.log(msg.channel, msg.method, JSON.stringify(msg.body)); }; ws.onclose = function() { console.log('Disconnected, trying again in 3 seconds'); setTimeout(connect, 3000); }; } connect(); ``` ## Run it ```bash node listen.js ``` Send an order, then remove it: ```bash curl -X POST -H "Content-Type: application/json" -d '{"id":1002,"status":"paid"}' "https://sync.example.com/sync/orders/" curl -X DELETE "https://sync.example.com/sync/orders/?id=1002" ``` The script prints, also across a restart of OpenSync: ```text Connected to Demo sync orders POST {"id":1002,"status":"paid"} Disconnected, trying again in 3 seconds Connected to Demo sync orders DELETE "" ``` Messages sent while the script was disconnected are not delivered later. ## Send from the same script To send a message to the other clients, call `send` on the open connection: ```js ws.send(JSON.stringify({ type: 'notify', channel: 'chat', body: { text: 'Hello' } })); ``` See [WebSocket](../../reference/websocket/). --- title: Listen in a web page project: OpenSync version: 1.0 section: recipes language: en license: MIT url: https://totaljs.es/docs/opensync/1-0/recipes/web-page/ updated: 2026-11-19T09:22:09.965Z --- # Listen in a web page > Show live messages in a web page with the browser WebSocket. A web page can connect to OpenSync with the browser's `WebSocket`, also when the page is on another address. Use a token limited to the channels the page needs: everyone who opens the page can read the token in its source. ## The page ```html