1 # parent-module [![Build Status](https://travis-ci.org/sindresorhus/parent-module.svg?branch=master)](https://travis-ci.org/sindresorhus/parent-module)
3 > Get the path of the parent module
5 Node.js exposes `module.parent`, but it only gives you the first cached parent, which is not necessarily the actual parent.
11 $ npm install parent-module
19 const parentModule = require('parent-module');
21 module.exports = () => {
22 console.log(parentModule());
23 //=> '/Users/sindresorhus/dev/unicorn/foo.js'
29 const bar = require('./bar');
37 ### parentModule([filepath])
39 By default, it will return the path of the immediate parent.
44 Default: [`__filename`](https://nodejs.org/api/globals.html#globals_filename)
46 Filepath of the module of which to get the parent path.
48 Useful if you want it to work [multiple module levels down](https://github.com/sindresorhus/parent-module/tree/master/fixtures/filepath).
53 Combine it with [`read-pkg-up`](https://github.com/sindresorhus/read-pkg-up) to read the package.json of the parent module.
56 const path = require('path');
57 const readPkgUp = require('read-pkg-up');
58 const parentModule = require('parent-module');
60 console.log(readPkgUp.sync({cwd: path.dirname(parentModule())}).pkg);
61 //=> {name: 'chalk', version: '1.0.0', …}
67 MIT © [Sindre Sorhus](https://sindresorhus.com)