npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

nlocks

v1.0.1

Published

A Node.js library providing asynchronous locking mechanisms including in-memory locks and file-based locks

Readme

nlocks

A Node.js library providing asynchronous locking mechanisms including in-memory locks and file-based locks for coordinating access to resources across concurrent processes.

Features

  • AsyncLock: In-memory asynchronous lock for coordinating access to resources within a single process
  • FileLock: File-based lock for coordinating access to resources across multiple processes
  • TCPLock: TCP-based distributed lock for coordinating access to resources across multiple machines
  • Lightweight and easy to use
  • Promise-based API
  • Comprehensive test coverage

Installation

npm install nlocks

Usage

Via index.js (recommended)

const { AsyncLock, FileLock } = require('nlocks');

const asyncLock = new AsyncLock();
const fileLock = new FileLock();

AsyncLock

An in-memory lock for synchronizing async operations within a single Node.js process:

const AsyncLock = require('nlocks/async-lock');

const lock = new AsyncLock();

async function protectedOperation() {
  await lock.acquire();
  try {
    // Your critical section code here
    console.log('Performing protected operation');
    await someAsyncWork();
  } finally {
    lock.release();
  }
}

FileLock

A file-based lock for synchronizing operations across multiple Node.js processes:

const FileLock = require('nlocks/file-lock');

const lock = new FileLock();

async function fileProtectedOperation() {
  await lock.acquire('/path/to/your/file.txt');
  try {
    // Your file operation code here
    console.log('Performing file operation');
    await someFileAsyncWork();
  } finally {
    lock.release('/path/to/your/file.txt');
  }
}

TCPLock

A TCP-based distributed lock for synchronizing operations across multiple machines:

Server side

const TCPLockServer = require('nlocks/lock.tcp');

// Create and start a TCP lock server
const server = new TCPLockServer({
  host: '0.0.0.0',  // Listen host
  port: 7301        // Listen port
});

server.start();

Client side

const TcpRwLock = require('nlocks/lock-client.tcp');

// Create a TCP lock client
const lock = new TcpRwLock('resource-name', {
  connect: {
    host: 'localhost',  // Server host
    port: 7301          // Server port
  }
});

async function tcpProtectedOperation() {
  await lock.connect();  // Connect to the lock server
  try {
    await lock.readLock();   // Acquire a read lock
    // Or use await lock.writeLock(); for a write lock
    
    // Your critical section code here
    console.log('Performing protected operation');
    await someAsyncWork();
  } finally {
    await lock.unlock();     // Release the lock
    await lock.close(); // Disconnect from server
  }
}

API

AsyncLock

  • new AsyncLock() - Creates a new AsyncLock instance
  • acquire(): Promise<void> - Acquires the lock
  • release(): void - Releases the lock

FileLock

  • new FileLock() - Creates a new FileLock instance
  • acquire(filePath): Promise<void> - Acquires a lock for the specified file path
  • release(filePath): void - Releases the lock for the specified file path

TCPLock

Server

  • new TCPLockServer(options) - Creates a new TCP lock server instance
    • options.host: Host to listen on (default: '0.0.0.0')
    • options.port: Port to listen on (default: 7301)
  • start(): void - Starts the lock server
  • stop(): void - Stops the lock server

Client

  • new TcpRwLock(resource, options) - Creates a new TCP lock client instance
    • resource: Name of the resource to lock
    • options.connect.host: Server hostname to connect to (default: 'localhost')
    • options.connect.port: Server port to connect to (default: 7301)
  • connect(): Promise<void> - Connects to the lock server
  • readLock(): Promise<void> - Acquires a read lock
  • writeLock(): Promise<void> - Acquires a write lock
  • unlock(): Promise<void> - Releases the currently held lock

Testing

Run the test suite with:

npm test

License

MIT