
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
pm2-exclusive-lock
Advanced tools
Retrieve a lock for a specific node instance to provide mutually exclusive access to a shared resource
This library aims to solve a situation when you need to retrieve a lock to provide mutually exclusive access to a shared resource. Works in the PM2 environment (cluster) and also on a single instance. The library does not use any external database or synchronizer and works purely on direct communication between processes.
Does this library help you? Do not forget to give it a ⭐️!
yarn add pm2-exclusive-lock
npm install pm2-exclusive-lock
Without custom configuration
import { LockService } from 'pm2-exclusive-lock'
const lockService = new LockService()
lockService.lock(async () => {
// your code goes here 🚀
})
// On application shutdown, destroy the instance
// to allow process to send a "DISCONNECT" message to the other nodes
// and deallocate binded handlers
lockService.destroy()
With custom configuration
import { LockService, LOCK_ERROR_RESOLUTION } from 'pm2-exclusive-lock'
const lockService = new LockService({
groupId: 'FS_LOCK',
lockTimeout: 10 * 1000, // 10 seconds,
syncTimeout: 1.5 * 1000, // 1.5 seconds,
lockErrorResolution: LOCK_ERROR_RESOLUTION.THROW, // or LOCK_ERROR_RESOLUTION.IGNORE
logger: {
debug: console.debug,
warn: console.warn,
error: console.error
}
})
lockService.lock(async () => {
// your code goes here 🚀
})
// On application shutdown, destroy the instance
// to allow process to send a "DISCONNECT" message to the other nodes
lockService.destroy()
interface IConfig {
logger?: ILogger;
lockTimeout?: number; // miliseconds
lockTimeoutResolution?: LOCK_TIMEOUT_RESOLUTION; // 'THROW' or 'IGNORE'
syncTimeout?: number; // miliseconds
groupId?: string; // name of lock group
}
interface ILogger {
debug: (msg: string) => void;
warn: (msg: string) => void;
error: (msg: string, err: Error) => void;
}
FAQs
Retrieve a lock for a specific node instance to provide mutually exclusive access to a shared resource
We found that pm2-exclusive-lock demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.