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();
Errors
Common errors & fixes
Access denied for user 'root'@'localhost'
MySQL user lacks REPLICATION SLAVE and REPLICATION CLIENT privileges.
fixGRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'root'@'localhost';
Cannot connect to MySQL server on 'localhost:3306'
MySQL server not running or incorrect credentials.
fixVerify MySQL is running, host/port correct, and firewall allows connection.
TypeError: watcher.on is not a function
Using CommonJS require without default import access.
fixUse import BinlogWatcher from 'mysql-binlog-events' or const { BinlogWatcher } = require('mysql-binlog-events') 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)