1. find-parent-dir
Finds the first parent directory that contains a given file or directory.
find-parent-dir
Package: find-parent-dir
Created by: thlorenz
Last modified: Sat, 18 Jun 2022 00:55:36 GMT
Version: 0.3.1
License: MIT
Downloads: 1,714,928
Repository: https://github.com/thlorenz/find-parent-dir

Install

npm install find-parent-dir
yarn add find-parent-dir

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

Dependencies

RELATED POST

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin