{"_id":"parent-module","_rev":"3759205","name":"parent-module","description":"Get the path of the parent module","dist-tags":{"latest":"3.1.0"},"maintainers":[{"name":"sindresorhus","email":""}],"time":{"modified":"2025-03-27T07:14:09.000Z","created":"2016-01-22T15:05:41.453Z","3.1.0":"2023-09-14T06:26:34.494Z","3.0.0":"2021-10-04T08:13:36.738Z","2.0.0":"2019-04-30T14:16:53.267Z","1.0.1":"2019-03-28T11:33:52.331Z","1.0.0":"2018-12-25T15:51:03.878Z","0.1.0":"2016-01-22T15:05:41.453Z"},"users":{"nraibaud":true},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"repository":{"type":"git","url":"git+https://github.com/sindresorhus/parent-module.git"},"versions":{"3.1.0":{"name":"parent-module","version":"3.1.0","description":"Get the path of the parent module","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/parent-module.git"},"funding":"https://github.com/sponsors/sindresorhus","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"type":"module","exports":"./index.js","engines":{"node":"^12.20.0 || ^14.13.1 || >=16.0.0"},"scripts":{"test":"xo && ava && tsd"},"keywords":["parent","module","package","caller","calling","module","path","callsites","callsite","stacktrace","stack","trace","function","file"],"dependencies":{"callsites":"^4.1.0"},"devDependencies":{"ava":"^3.15.0","execa":"^5.1.1","tsd":"^0.17.0","xo":"^0.45.0"},"types":"./index.d.ts","gitHead":"f579e1737e12b120650997e16fef12dbced4938b","bugs":{"url":"https://github.com/sindresorhus/parent-module/issues"},"homepage":"https://github.com/sindresorhus/parent-module#readme","_id":"parent-module@3.1.0","_nodeVersion":"18.16.1","_npmVersion":"9.2.0","dist":{"shasum":"bcba90b465fa3ba029fad2a933f4c683668a2148","size":2342,"noattachment":false,"key":"/parent-module/-/parent-module-3.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/parent-module/download/parent-module-3.1.0.tgz"},"_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"directories":{},"maintainers":[{"name":"sindresorhus","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/parent-module_3.1.0_1694672794314_0.07498039719627103"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2023-09-14T06:26:34.494Z","publish_time":1694672794494,"_source_registry_name":"default","_cnpm_publish_time":1694672794494},"3.0.0":{"name":"parent-module","version":"3.0.0","description":"Get the path of the parent module","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/parent-module.git"},"funding":"https://github.com/sponsors/sindresorhus","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"type":"module","exports":"./index.js","engines":{"node":"^12.20.0 || ^14.13.1 || >=16.0.0"},"scripts":{"test":"xo && ava && tsd"},"keywords":["parent","module","package","caller","calling","module","path","callsites","callsite","stacktrace","stack","trace","function","file"],"dependencies":{"callsites":"^4.0.0"},"devDependencies":{"ava":"^3.15.0","execa":"^5.1.1","tsd":"^0.17.0","xo":"^0.45.0"},"gitHead":"e99192a8f6870dde49947643c7324a3797515de6","bugs":{"url":"https://github.com/sindresorhus/parent-module/issues"},"homepage":"https://github.com/sindresorhus/parent-module#readme","_id":"parent-module@3.0.0","_nodeVersion":"12.22.1","_npmVersion":"7.20.3","dist":{"shasum":"4bddc5cc0584935189977bae3384cc66dedde363","size":2346,"noattachment":false,"key":"/parent-module/-/parent-module-3.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/parent-module/download/parent-module-3.0.0.tgz"},"_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"directories":{},"maintainers":[{"name":"sindresorhus","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/parent-module_3.0.0_1633335216602_0.5745603950022955"},"_hasShrinkwrap":false,"publish_time":1633335216738,"_cnpm_publish_time":1633335216738},"2.0.0":{"name":"parent-module","version":"2.0.0","description":"Get the path of the parent module","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/parent-module.git"},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"sindresorhus.com"},"engines":{"node":">=8"},"scripts":{"test":"xo && ava && tsd"},"keywords":["parent","module","package","caller","calling","module","path","callsites","callsite","stacktrace","stack","trace","function","file"],"dependencies":{"callsites":"^3.1.0"},"devDependencies":{"ava":"^1.4.1","execa":"^1.0.0","tsd":"^0.7.2","xo":"^0.24.0"},"gitHead":"1923bf8f724f7f2e77a2c893116285a8b0a47598","bugs":{"url":"https://github.com/sindresorhus/parent-module/issues"},"homepage":"https://github.com/sindresorhus/parent-module#readme","_id":"parent-module@2.0.0","_nodeVersion":"8.16.0","_npmVersion":"6.9.0","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"dist":{"shasum":"fa71f88ff1a50c27e15d8ff74e0e3a9523bf8708","size":2179,"noattachment":false,"key":"/parent-module/-/parent-module-2.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/parent-module/download/parent-module-2.0.0.tgz"},"maintainers":[{"name":"sindresorhus","email":""}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/parent-module_2.0.0_1556633813147_0.3310203047620397"},"_hasShrinkwrap":false,"publish_time":1556633813267,"_cnpm_publish_time":1556633813267},"1.0.1":{"name":"parent-module","version":"1.0.1","description":"Get the path of the parent module","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/parent-module.git"},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"sindresorhus.com"},"engines":{"node":">=6"},"scripts":{"test":"xo && ava"},"keywords":["parent","module","package","pkg","caller","calling","module","path","callsites","callsite","stacktrace","stack","trace","function","file"],"dependencies":{"callsites":"^3.0.0"},"devDependencies":{"ava":"^1.4.1","execa":"^1.0.0","xo":"^0.24.0"},"gitHead":"48267d001c4d215ba21a701a6882dba30fb8d614","bugs":{"url":"https://github.com/sindresorhus/parent-module/issues"},"homepage":"https://github.com/sindresorhus/parent-module#readme","_id":"parent-module@1.0.1","_nodeVersion":"8.15.0","_npmVersion":"6.9.0","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"dist":{"shasum":"691d2709e78c79fae3a156622452d00762caaaa2","size":2008,"noattachment":false,"key":"/parent-module/-/parent-module-1.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/parent-module/download/parent-module-1.0.1.tgz"},"maintainers":[{"name":"sindresorhus","email":""}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/parent-module_1.0.1_1553772832186_0.1578223180001468"},"_hasShrinkwrap":false,"publish_time":1553772832331,"_cnpm_publish_time":1553772832331},"1.0.0":{"name":"parent-module","version":"1.0.0","description":"Get the path of the parent module","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/parent-module.git"},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"sindresorhus.com"},"engines":{"node":">=6"},"scripts":{"test":"xo && ava"},"keywords":["parent","module","package","pkg","caller","calling","module","path","callsites","callsite","stacktrace","stack","trace","function","file"],"dependencies":{"callsites":"^3.0.0"},"devDependencies":{"ava":"^1.0.1","execa":"^1.0.0","xo":"^0.23.0"},"gitHead":"21d44dd4d566218c6abd1b8747469756fba455d6","bugs":{"url":"https://github.com/sindresorhus/parent-module/issues"},"homepage":"https://github.com/sindresorhus/parent-module#readme","_id":"parent-module@1.0.0","_npmVersion":"6.4.1","_nodeVersion":"11.5.0","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"dist":{"shasum":"df250bdc5391f4a085fb589dad761f5ad6b865b5","size":1989,"noattachment":false,"key":"/parent-module/-/parent-module-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/parent-module/download/parent-module-1.0.0.tgz"},"maintainers":[{"name":"sindresorhus","email":""}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/parent-module_1.0.0_1545753063775_0.45941122354092845"},"_hasShrinkwrap":false,"publish_time":1545753063878,"_cnpm_publish_time":1545753063878},"0.1.0":{"name":"parent-module","version":"0.1.0","description":"Get the path of the parent module","license":"MIT","repository":{"type":"git","url":"https://github.com/sindresorhus/parent-module"},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"sindresorhus.com"},"engines":{"node":">=0.10.0"},"scripts":{"test":"xo && ava"},"files":["index.js"],"keywords":["parent","module","package","pkg","caller","calling","module","path","callsites","callsite","stacktrace","stack","trace","function","file"],"dependencies":{"callsites":"^1.0.0"},"devDependencies":{"ava":"*","execa":"^0.2.2","xo":"*"},"gitHead":"0ebdd4a7582d4cee30ca2151fbd592b4b3b20ff2","bugs":{"url":"https://github.com/sindresorhus/parent-module/issues"},"homepage":"https://github.com/sindresorhus/parent-module","_id":"parent-module@0.1.0","_shasum":"b5292863a1e8c476ecf857e7d75c98920b24b8a6","_from":".","_npmVersion":"2.14.12","_nodeVersion":"4.2.4","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"dist":{"shasum":"b5292863a1e8c476ecf857e7d75c98920b24b8a6","size":2058,"noattachment":false,"key":"/parent-module/-/parent-module-0.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/parent-module/download/parent-module-0.1.0.tgz"},"maintainers":[{"name":"sindresorhus","email":""}],"directories":{},"publish_time":1453475141453,"_cnpm_publish_time":1453475141453,"_hasShrinkwrap":false}},"readme":"# parent-module\n\n> Get the path of the parent module\n\nNode.js exposes `module.parent`, but it only gives you the first cached parent, which is not necessarily the actual parent.\n\n## Install\n\n```sh\nnpm install parent-module\n```\n\n## Usage\n\n```js\n// bar.js\nimport parentModule from 'parent-module';\n\nexport default function bar() {\n\tconsole.log(parentModule());\n\t//=> '/Users/sindresorhus/dev/unicorn/foo.js'\n};\n```\n\n```js\n// foo.js\nimport bar from './bar.js';\n\nbar();\n```\n\n## API\n\n### parentModule(filePath?)\n\nBy default, it will return the path of the immediate parent.\n\n#### filePath\n\nType: `string`\\\nDefault: [`__filename`](https://nodejs.org/api/globals.html#globals_filename)\n\nThe file path of the module of which to get the parent path.\n\nUseful if you want it to work [multiple module levels down](fixtures/filepath).\n\n## Tip\n\nCombine it with [`read-pkg-up`](https://github.com/sindresorhus/read-pkg-up) to read the package.json of the parent module.\n\n```js\nimport path from 'node:path';\nimport {readPackageUpSync} from 'read-pkg-up';\nimport parentModule from 'parent-module';\n\nconsole.log(readPackageUpSync({cwd: path.dirname(parentModule())}).pkg);\n//=> {name: 'chalk', version: '1.0.0', …}\n```\n\n---\n\n<div align=\"center\">\n\t<b>\n\t\t<a href=\"https://tidelift.com/subscription/pkg/npm-parent-module?utm_source=npm-parent-module&utm_medium=referral&utm_campaign=readme\">Get professional support for this package with a Tidelift subscription</a>\n\t</b>\n\t<br>\n\t<sub>\n\t\tTidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.\n\t</sub>\n</div>\n","_attachments":{},"homepage":"https://github.com/sindresorhus/parent-module#readme","bugs":{"url":"https://github.com/sindresorhus/parent-module/issues"},"license":"MIT"}