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 🙏

© 2024 – Pkg Stats / Ryan Hefner

lockfile

v1.0.4

Published

A very polite lock file utility, which endeavors to not litter, and to wait patiently for others.

Downloads

5,388,432

Readme

lockfile

A very polite lock file utility, which endeavors to not litter, and to wait patiently for others.

Usage

var lockFile = require('lockfile')

// opts is optional, and defaults to {}
lockFile.lock('some-file.lock', opts, function (er) {
  // if the er happens, then it failed to acquire a lock.
  // if there was not an error, then the file was created,
  // and won't be deleted until we unlock it.

  // do my stuff, free of interruptions
  // then, some time later, do:
  lockFile.unlock('some-file.lock', function (er) {
    // er means that an error happened, and is probably bad.
  })
})

Methods

Sync methods return the value/throw the error, others don't. Standard node fs stuff.

All known locks are removed when the process exits. Of course, it's possible for certain types of failures to cause this to fail, but a best effort is made to not be a litterbug.

lockFile.lock(path, [opts], cb)

Acquire a file lock on the specified path

lockFile.lockSync(path, [opts])

Acquire a file lock on the specified path

lockFile.unlock(path, cb)

Close and unlink the lockfile.

lockFile.unlockSync(path)

Close and unlink the lockfile.

lockFile.check(path, [opts], cb)

Check if the lockfile is locked and not stale.

Callback is called with cb(error, isLocked).

lockFile.checkSync(path, [opts])

Check if the lockfile is locked and not stale.

Returns boolean.

Options

opts.wait

A number of milliseconds to wait for locks to expire before giving up. Only used by lockFile.lock. Poll for opts.wait ms. If the lock is not cleared by the time the wait expires, then it returns with the original error.

opts.pollPeriod

When using opts.wait, this is the period in ms in which it polls to check if the lock has expired. Defaults to 100.

opts.stale

A number of milliseconds before locks are considered to have expired.

opts.retries

Used by lock and lockSync. Retry n number of times before giving up.

opts.retryWait

Used by lock. Wait n milliseconds before retrying.