Registry / database / mysql-binlog-events

mysql-binlog-events

JSON →
library0.1.18jsnpmunverified

A MySQL binlog listener library built on top of zongji. Version 0.1.18. It provides event-based access to MySQL binary log changes (row-based replication events) such as insert, update, delete, and table map events. Supports TypeScript types. Compared to alternatives like zongji, this package simplifies the API with a more event-driven approach. Release cadence is irregular; last update was several years ago.

npm install mysql-binlog-events
INSTALL
IMPORT
SIG · MYSQL-BINLOG-EVENT
M
mysql-binlog-events
databasejavascriptv0.1.18
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

BinlogWatcher
import { BinlogWatcher } from 'mysql-binlog-events'
const BinlogWatcher = require('mysql-binlog-events').BinlogWatcher
ESM import is recommended. CommonJS require with destructuring may fail if module uses ESM only.
default export (BinlogWatcher)
import BinlogWatcher from 'mysql-binlog-events'
const BinlogWatcher = require('mysql-binlog-events')
The package exports a default class BinlogWatcher. CommonJS require works if the module is CJS-compatible, but ES import is safer.
BinlogEvent type
import type { BinlogEvent } from 'mysql-binlog-events'
For TypeScript users, import type for event interfaces. Not available in CJS.
RowEvent type
import type { RowEvent } from 'mysql-binlog-events'
For TypeScript users, import type for row-level event typings.

Creates a BinlogWatcher instance, connects to MySQL, listens for binlog events (insert, update, delete) and handles errors.

import BinlogWatcher from 'mysql-binlog-events'; const watcher = new BinlogWatcher({ host: 'localhost', port: 3306, user: 'root', password: process.env.MYSQL_PASSWORD ?? '', serverId: 1, // must be unique among replicas filename: 'mysql-bin.000001', // optional: start from a specific binlog file position: 0 // optional: start position }); watcher.on('insert', (event) => { console.log('Insert:', event); }); watcher.on('update', (event) => { console.log('Update:', event); }); watcher.on('delete', (event) => { console.log('Delete:', event); }); watcher.on('error', (err) => { console.error('Error:', err); }); watcher.start();
Debug
Known issues
gotchaMySQL server must have binlog_format = ROW and log_bin enabled. Without these, the watcher will not receive events.
fix
Set MySQL config: binlog_format=ROW, log_bin=ON, and ensure server_id is set.
affects: >=0.0.0
gotchaEach replica must have a unique server_id. Duplicate server_id causes connection issues.
fix
Pass a unique serverId to the constructor.
affects: >=0.0.0
gotchaThe watcher only supports row-based binlog events. Statement-based or mixed mode may not work correctly.
fix
Ensure MySQL binlog_format is set to ROW.
affects: >=0.0.0
deprecatedzongji (core dependency) has been archived. Future MySQL versions may break compatibility.
fix
Consider alternative libraries like @rodrigogs/mysql-events or direct use of mysql2 if needed.
affects: >=0.0.0
Errors
Common errors & fixes
Access denied for user 'root'@'localhost'
MySQL user lacks REPLICATION SLAVE and REPLICATION CLIENT privileges.
fix
GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'root'@'localhost';
Cannot connect to MySQL server on 'localhost:3306'
MySQL server not running or incorrect credentials.
fix
Verify MySQL is running, host/port correct, and firewall allows connection.
TypeError: watcher.on is not a function
Using CommonJS require without default import access.
fix
Use import BinlogWatcher from 'mysql-binlog-events' or const { BinlogWatcher } = require('mysql-binlog-events')
Upgrade
Version history
0.1.18latest on npm
Audit
Dependencies
zongjirequiredCore dependency that handles MySQL binlog connection and parsing; this package wraps zongji's API
mysql2requiredUsed for MySQL connection (zongji depends on it)
Agent activity
2 hits · last 30 days
node
2
Resources
mysql-binlog-events — npm install mysql-binlog-events · libregistry