Skip to content
Infer the owner of a path based on the owner of its nearest existing parent
Branch: master
Clone or download
Latest commit 264706f Jul 19, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.
test test Jul 19, 2019
.gitignore ignore stuff Jul 19, 2019
LICENSE isc license Jul 19, 2019 drop the scope on package name Jul 19, 2019
index.js code to make tests pass Jul 19, 2019
package-lock.json 1.0.4 Jul 19, 2019
package.json 1.0.4 Jul 19, 2019


Infer the owner of a path based on the owner of its nearest existing parent


const inferOwner = require('infer-owner')

inferOwner('/some/cache/folder/file').then(owner => {
  // owner is {uid, gid} that should be attached to
  // the /some/cache/folder/file, based on ownership
  // of /some/cache/folder, /some/cache, /some, or /,
  // whichever is the first to exist

// same, but not async
const owner = inferOwner.sync('/some/cache/folder/file')

// results are cached!  to reset the cache (eg, to change
// permissions for whatever reason), do this:

This module endeavors to be as performant as possible. Parallel requests for ownership of the same path will only stat the directories one time.


  • inferOwner(path) -> Promise<{ uid, gid }>

    If the path exists, return its uid and gid. If it does not, look to its parent, then its grandparent, and so on.

  • inferOwner(path) -> { uid, gid }

    Sync form of inferOwner(path).

  • inferOwner.clearCache()

    Delete all cached ownership information and in-flight tracking.

You can’t perform that action at this time.