Cross-process file locking solution with lock-queue for Node.js. Current stable version 2.2.0, released with TypeScript support. Uses file-based locking with a lock queue and configurable timeouts (lock timeout defaults to 20 minutes, wait timeout defaults to 10 seconds). Includes a convenient withLock wrapper for automatic lock/unlock. Ships TypeScript declarations. Key differentiator: simple async/await interface and lock queue mechanism rather than requiring external lock servers.
npm install cross-process-lockNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Demonstrates acquiring a lock on a file, performing a write/read operation, and releasing the lock with error handling via try/finally.
Use const release = await lock(file); call release() to unlock. For 1.x, use lock(file).then(l => l.release()).
Migrate to using the release function returned by lock().
Use absolute paths for consistency across processes.
Set lockTimeout to a higher value if needed, but be aware of stale locks.
Adjust waitTimeout according to expected contention.
Use const { lock } = require('cross-process-lock') or import { lock } from 'cross-process-lock'.Ensure the directory exists and is writable, or use an absolute path for the target file.
Increase waitTimeout, or check that the other process releases the lock promptly.
Manually delete the .lock file if you are sure no other process holds it.