A semaphore handler for Node.js using MySQL as the coordination backend. Current stable version 0.1.1. No recent releases. Provides lock, unlock, and islocked methods via Promises for clustered Node.js environments where you need to ensure only one instance runs a task (e.g., cron jobs). Key differentiators: simple MySQL-based semaphore with no external dependencies beyond mysql package. Known issues: lock name uniqueness is critical to avoid accidental unlocking across applications; no automatic lock cleanup.
npm install mysql-semaphoreNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows how to initialize the semaphore, acquire a lock with a 5-second timeout, perform work, and release the lock.
Use a naming convention that includes application name, database, and purpose, e.g., 'myapp_mydb_myprocess'.
Implement a heartbeat or TTL mechanism externally, or set up a cleanup cron job.
Review the custom locking mechanism in source code; consider using MySQL's built-in GET_LOCK() as an alternative.
Create the table manually: CREATE TABLE IF NOT EXISTS semaphore (lockName VARCHAR(255) PRIMARY KEY, lockTime DATETIME);
Use import Semaphore from 'mysql-semaphore' (default import).