Registry / database / mysql-event-emitter

mysql-event-emitter

JSON →
library1.0.8jsnpmunverified

A Node.js library that turns MySQL/MariaDB binary logs into real-time events using the EventEmitter pattern. Current stable version: 1.0.8. It monitors row changes, DDL, and query logs via replication protocol. Differentiator: lightweight, zero external dependencies, pure JavaScript implementation for MySQL 5.6+ and MariaDB 10+. Release cadence is low; last update was in 2021.

npm install mysql-event-emitter
INSTALL
IMPORT
SIG · MYSQL-EVENT-EMITTE
M
mysql-event-emitter
databasejavascriptv1.0.8
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.

MySQLEventEmitter
import MySQLEventEmitter from 'mysql-event-emitter'
const MySQLEventEmitter = require('mysql-event-emitter')
Default ES module import only. CJS require may fail if the project uses ESM; check if your Node version supports ESM.
MySQLEventEmitter
import MySQLEventEmitter from 'mysql-event-emitter'
import { MySQLEventEmitter } from 'mysql-event-emitter'
The package exports a single default class, not a named export. Always use default import syntax.
Event
import MySQLEventEmitter from 'mysql-event-emitter' const emitter = new MySQLEventEmitter() emitter.on('row', (event) => {})
emitter.on('row', console.log(event))
Event names are strings('row', 'ddl', 'query'). The event payload is an object with type-specific fields.

This example initializes a MySQLEventEmitter to listen for row changes, DDL events, and queries, then starts the emitter and stops after 60 seconds.

import MySQLEventEmitter from 'mysql-event-emitter'; const emitter = new MySQLEventEmitter({ host: 'localhost', user: 'root', password: process.env.MYSQL_PASSWORD ?? '', database: 'test', serverId: 1 }); emitter.on('row', (event) => { console.log('Row changed:', event); }); emitter.on('ddl', (event) => { console.log('Schema changed:', event); }); emitter.on('query', (event) => { console.log('Query executed:', event); }); emitter.start(); setTimeout(() => { emitter.stop(); }, 60000);
Debug
Known issues
gotchaServer ID must be unique among replication slaves; using the same serverId on multiple instances can cause replication conflicts.
fix
Assign a unique numeric serverId (e.g., based on host IP hash) for each emitter instance.
affects: >=0.0.0
breakingIn version 1.0.0 the API changed from callback-based to EventEmitter. Old code using 'onRow' callbacks will not work.
fix
Use emitter.on('row', callback) instead of passing callbacks to constructor.
affects: <1.0.0
gotchaRequires MySQL binary logging to be enabled with row-based format. If binary logging is off or uses statement-based, no events will fire.
fix
Set MySQL server configuration: log_bin=ON, binlog_format=ROW. For MariaDB, enable binlog with mixed or row format.
affects: >=0.0.0
gotchaPassword must be provided in plain text in constructor options; no support for authentication plugins like caching_sha2_password.
fix
Use only mysql_native_password authentication plugin user. Consider wrapping credentials via environment variables.
affects: >=0.0.0
deprecatedThe 'query' event may be removed in future versions; it relies on parsing general query log events which are not always consistent across MySQL versions.
fix
Avoid relying on 'query' event for production systems. Use 'row' and 'ddl' events instead.
affects: ==1.0.8
Errors
Common errors & fixes
Error: ER_NET_PACKET_TOO_LARGE: Got a packet bigger than 'max_allowed_packet' bytes
The binary log event size exceeds the MySQL server's max_allowed_packet limit.
fix
Increase max_allowed_packet on both MySQL server and in emitter options (e.g., max_allowed_packet: 1024 * 1024 * 16).
Error: Lost connection to MySQL server during query
Network instability or server timeout while reading binlog stream.
fix
Increase connect timeout, enable TCP keepalive, or implement reconnection logic. In emitter options: connectTimeout: 10000.
TypeError: emitter.on is not a function
Wrong import style; the package exports a class but user may have imported the default incorrectly (e.g., using named import).
fix
Ensure default import is used: import MySQLEventEmitter from 'mysql-event-emitter'.
Upgrade
Version history
1.0.8latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
mysql-event-emitter — npm install mysql-event-emitter · libregistry