Popularity
1.5
Growing
Activity
0.0
Declining
63
5
1

Monthly Downloads: 0
Programming language: JavaScript
License: MIT License
Tags: Miscellaneous     Stack     Module     Path     Trace     Function     File     Package     Callsites     Callsite     Stacktrace     Pkg     Parent     Calling     Caller    
Latest version: v2.0.0

parent-module alternatives and similar modules

Based on the "Miscellaneous" category

Do you think we are missing an alternative of parent-module or a related project?

Add another 'Miscellaneous' Module

README

parent-module Build Status

Get the path of the parent module

Node.js exposes module.parent, but it only gives you the first cached parent, which is not necessarily the actual parent.

Install

$ npm install parent-module

Usage

// bar.js
const parentModule = require('parent-module');

module.exports = () => {
    console.log(parentModule());
    //=> '/Users/sindresorhus/dev/unicorn/foo.js'
};
// foo.js
const bar = require('./bar');

bar();

API

parentModule(filePath?)

By default, it will return the path of the immediate parent.

filePath

Type: string Default: __filename

File path of the module of which to get the parent path.

Useful if you want it to work multiple module levels down.

Tip

Combine it with read-pkg-up to read the package.json of the parent module.

const path = require('path');
const readPkgUp = require('read-pkg-up');
const parentModule = require('parent-module');

console.log(readPkgUp.sync({cwd: path.dirname(parentModule())}).pkg);
//=> {name: 'chalk', version: '1.0.0', …}

Get professional support for this package with a Tidelift subscription Tidelift helps make open source sustainable for maintainers while giving companiesassurances about security, maintenance, and licensing for their dependencies.