Socket
Socket
Sign inDemoInstall

find-parent-dir

Package Overview
Dependencies
0
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

find-parent-dir

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


Version published
Maintainers
1
Weekly downloads
406,248
decreased by-10.01%

Weekly downloads

Readme

Source

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); 
}

Keywords

FAQs

Last updated on 14 May 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc