Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/thlorenz/find-parent-dir
Finds the first parent directory that contains a given file or directory.
https://github.com/thlorenz/find-parent-dir
Last synced: 3 days ago
JSON representation
Finds the first parent directory that contains a given file or directory.
- Host: GitHub
- URL: https://github.com/thlorenz/find-parent-dir
- Owner: thlorenz
- License: mit
- Created: 2013-05-25T20:36:20.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2021-05-14T16:47:32.000Z (over 3 years ago)
- Last Synced: 2024-12-09T05:07:01.799Z (13 days ago)
- Language: JavaScript
- Homepage:
- Size: 10.7 KB
- Stars: 24
- Watchers: 4
- Forks: 8
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# find-parent-dir [![build status](https://secure.travis-ci.org/thlorenz/find-parent-dir.png)](http://travis-ci.org/thlorenz/find-parent-dir)
Finds the first parent directory that contains a given file or directory.
npm install find-parent-dir
```js
// 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);
}
```