开发者社区> 镜像站> NPM> find-parent-dir
find-parent-dir
Finds the first parent directory that contains a given file or directory.
Last updated 7 years ago by thlorenz .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install find-parent-dir 
SYNC missed versions from official npm registry.

find-parent-dir build status

Finds the first parent directory that contains a given file or directory.

npm install find-parent-dir
// assuming this is called from a file in a subdirectory of /myprojects/foo which contains .git directory
var findParentDir = require('find-parent-dir');

findParentDir(__dirname, '.git', function (err, dir) {
  // has err if some file access error occurred
  console.log(dir); // => /myprojects/foo/
  
  // if parent dir wasn't found, dir is null
})

// Same using `sync` method
var dir;
try { 
  dir = findParentDir.sync(__dirname, '.git');
  console.log(dir); // => /myprojects/foo/
  // if parent dir wasn't found, dir is null
} catch(err) {
  console.error('error', err); 
}

Current Tags

  • 0.3.0                                ...           latest (7 years ago)

4 Versions

  • 0.3.0                                ...           7 years ago
  • 0.2.1                                ...           7 years ago
  • 0.2.0                                ...           7 years ago
  • 0.1.0                                ...           8 years ago
Maintainers (1)
Downloads
Today 345
This Week 17,250
This Month 12,925
Last Day 4,250
Last Week 23,834
Last Month 97,980
Dependencies (0)
None
Dev Dependencies (1)
Dependents (157)