This small library is there to acquire a tcp based lock by opening a tcp-server. Since ports cannot be listened from more than 1 process we can use this behaviour to acquire a kind of lock based on tcp-port.
npm i --save https://github.com/7c/tcp-mutex
import { tryLock } from '@7c/tcp-mutex';
// somewhere in your main code entry
await tryLock(1337)
const { tryLock } = require('@7c/tcp-mutex');
tryLock(1337).then(()=>{
console.log("locked successfully");
// we can start our application here
}).catch(err=>{
console.log("This application already started");
process.exit(0);
});