Skip to content

Maaaartin/single-instance-lock

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Single Instance Lock

Single Instance Lock is a module enabling Node.js script running as single instance apps.

Installation

Use following command.

yarn install single-instance-lock

Usage

Creating simple locker

import { SingleInstanceLock, LockType } from 'single-instance-lock';

const locker = new SingleInstanceLock('some-id');

// creates a single instance lock
locker.lock(LockType.Last);

locker.on('locked', () => {
    // running as single instance
    // your code goes here
});

locker.on('error', (err) => {
    // app with this id is already running
});

locker.unlock(() => {
    // lock was removed        
});

Lock Types

    // ...
    // Keeps lock on the last executed instance and closes the previously executed ones
    locker.lock(LockType.Last);
    // ...

    // ...
    // Keeps lock on the first executed instance and closes the later executed ones
    locker.lock(LockType.First);
    // ...

License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published