{"id":18687252,"url":"https://github.com/junosuarez/find-root","last_synced_at":"2026-03-15T18:09:02.730Z","repository":{"id":12328342,"uuid":"14966421","full_name":"junosuarez/find-root","owner":"junosuarez","description":"recursively find the closest package.json","archived":false,"fork":false,"pushed_at":"2023-01-11T11:56:13.000Z","size":48,"stargazers_count":48,"open_issues_count":1,"forks_count":5,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-12T04:39:40.223Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/junosuarez.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-12-05T21:36:12.000Z","updated_at":"2024-03-30T17:25:51.000Z","dependencies_parsed_at":"2023-01-13T16:54:00.382Z","dependency_job_id":null,"html_url":"https://github.com/junosuarez/find-root","commit_stats":null,"previous_names":["suarasaur/find-root","js-n/find-root"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/junosuarez%2Ffind-root","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/junosuarez%2Ffind-root/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/junosuarez%2Ffind-root/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/junosuarez%2Ffind-root/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/junosuarez","download_url":"https://codeload.github.com/junosuarez/find-root/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248521350,"owners_count":21118053,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-07T10:32:07.382Z","updated_at":"2026-03-15T18:08:57.681Z","avatar_url":"https://github.com/junosuarez.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# find-root\nrecursively find the closest package.json\n\n[![Build Status](https://travis-ci.org/js-n/find-root.svg?branch=master)](https://travis-ci.org/js-n/find-root)\n\n## usage\nSay you want to check if the directory name of a project matches its\nmodule name in package.json:\n\n```js\nconst path = require('path')\nconst findRoot = require('find-root')\n\n// from a starting directory, recursively search for the nearest\n// directory containing package.json\nconst root = findRoot('/Users/jsdnxx/Code/find-root/tests')\n// =\u003e '/Users/jsdnxx/Code/find-root'\n\nconst dirname = path.basename(root)\nconsole.log('is it the same?')\nconsole.log(dirname === require(path.join(root, 'package.json')).name)\n```\n\nYou can also pass in a custom check function (by default, it checks for the\nexistence of `package.json` in a directory). In this example, we traverse up\nto find the root of a git repo:\n```js\nconst fs = require('fs')\n\nconst gitRoot = findRoot('/Users/jsdnxx/Code/find-root/tests', function (dir) {\n  return fs.existsSync(path.resolve(dir, '.git'))\n})\n```\n\n\n## api\n\n### `findRoot: (startingPath : string, check?: (dir: string) =\u003e boolean) =\u003e string`\n\nReturns the path for the nearest directory to `startingPath` containing\na `package.json` file, eg `/foo/module`.\n\nIf `check` is provided, returns the path for the closest parent directory\nwhere `check` returns true.\n\nThrows an error if no `package.json` is found at any level in the\n`startingPath`.\n\n\n## installation\n```sh\n\u003e npm install find-root\n```\n\n## running the tests\n\nFrom package root:\n```sh\n\u003e npm install\n\u003e npm test\n```\n\n## contributors\n\n- jsdnxx\n\n\n## license\nMIT. (c) 2017 jsdnxx\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjunosuarez%2Ffind-root","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjunosuarez%2Ffind-root","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjunosuarez%2Ffind-root/lists"}