lib/index.js
function findFile (startingPath) {
  try {
    return fs.readFileSync(startingPath, "utf8");
  }
  catch (e) {
    let fileName = path.basename(startingPath);
    let startingDir = path.dirname(startingPath);
    let parentDir = path.dirname(startingDir);

    if (parentDir === startingDir) {
      // We're recursed all the way to the root directory
      throw e;
    }
    else {
      try {
        // Search for the file in the parent directories
        return findFile(path.join(parentDir, fileName));
      }
      catch (e2) {
        // The file wasn't found in any of the parent directories
        throw ono(e,
          `Unable to find a file named "${fileName}" in "${startingDir}" or any of its parent directories.`
        );
      }
    }
  }
}
function findFile (startingPath) {
  try {
    return fs.readFileSync(startingPath, "utf8");
  }
  catch (e) {
    let fileName = path.basename(startingPath);
    let startingDir = path.dirname(startingPath);
    let parentDir = path.dirname(startingDir);

    if (parentDir === startingDir) {
      // We're recursed all the way to the root directory
      throw e;
    }
    else {
      try {
        // Search for the file in the parent directories
        return findFile(path.join(parentDir, fileName));
      }
      catch (e2) {
        // The file wasn't found in any of the parent directories
        throw ono(e,
          `Unable to find a file named "${fileName}" in "${startingDir}" or any of its parent directories.`
        );
      }
    }
  }
}
function findFile ( startingPath ) { try { return fs . readFileSync ( startingPath , "utf8" ) ; } catch ( e ) { let fileName = path . basename ( startingPath ) ; let startingDir = path . dirname ( startingPath ) ; let parentDir = path . dirname ( startingDir ) ; if ( parentDir === startingDir ) { // We're recursed all the way to the root directory throw e ; } else { try { // Search for the file in the parent directories return findFile ( path . join ( parentDir , fileName ) ) ; } catch ( e2 ) { // The file wasn't found in any of the parent directories throw ono ( e , ` ${ fileName } ${ startingDir } ` ) ; } } } }
Searches for the given file, starting in the given directory
and crawling up from there, and reads its contents.

@param {string} startingPath - The file path to start at
@returns {string|undefined}
Searches for the given file starting in the given directory and crawling up from there and reads its contents .