Installations
npm install module-parent
Developer Guide
Typescript
No
Module System
CommonJS
Min. Node Version
>=0.10
Node Version
5.5.0
NPM Version
3.3.12
Score
69.9
Supply Chain
98.3
Quality
75.1
Maintenance
100
Vulnerability
100
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (100%)
Love this project? Help keep it running — sponsor us today! 🚀
Developer
alykoshin
Download Statistics
Total Downloads
1,399,266
Last Day
402
Last Week
3,020
Last Month
12,581
Last Year
157,452
GitHub Statistics
MIT License
6 Commits
3 Watchers
1 Branches
1 Contributors
Updated on Feb 01, 2016
Package Meta Information
Latest Version
0.0.2
Package Id
module-parent@0.0.2
Size
4.81 kB
NPM Version
3.3.12
Node Version
5.5.0
Total Downloads
Cumulative downloads
Total Downloads
1,399,266
Last Day
-38.1%
402
Compared to previous day
Last Week
-0.6%
3,020
Compared to previous week
Last Month
51.8%
12,581
Compared to previous month
Last Year
-24.8%
157,452
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
module-parent
Get one of the module's parents, cleaning the require cache
If you have different needs regarding the functionality, please add a feature request.
Installation
1npm install --save module-parent
Usage
1var parentModule = require('module-parent')(module, 0); 2var parentName = parentModule && path.basename(parentModule.filename, '.js') || 'app';
Caution: this module clears require.cache
to resolve the filename for the parent modules (if numParentsToSkip
parameter is set, then require.cache
is set for all the module when going up to parent, except last parent).
By default, module.parent
points to the module which require
d this one at first time, not all the modules require
'ing it later.
That means, each time module loads as at first time and, for example, it's not possible to use singleton pattern for all the modules which uses package module-parent
.
Parameters
1var parentModule = require('module-parent')( 2 moduleToStart, // module to start from 3 numParentsToSkip // number of parents to skip; default: 0 4);
moduleToStart
Type: Object
Description: Module to start from. Usually equals to module
, means to determine parents of current module.
Mandatory
Default: none
numParentsToSkip
Type: Number Description: Number of parent module to skip. For example, if you need to find module.parent.parent, you need to set it to 1 etc. Optional Default: 0, means use parent of the module provided as first parameter.
Examples
Fragment of package require-dir-all:
var moduleParent = require('module-parent');
....
options._parentsToSkip = options._parentsToSkip || 0;
...
var originalModule = moduleParent(module, options._parentsToSkip);
var parentDir = path.dirname(originalModule.filename);
Fragment of package config-dir-all:
1var moduleParent = require('module-parent'); 2var originalModule = moduleParent(module, 0); 3var parentDir = path.dirname(originalModule.filename);
Fragment of package mini-rest-logger:
1var parent = require('module-parent')(module, 1); 2var parentName = parent && path.basename(parent.filename, '.js') || 'app';
Credits
Links to package pages:
github.com  npmjs.com  travis-ci.org  coveralls.io  inch-ci.org
License
MIT

No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
Found 0/6 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
- Warn: no pull requests merged into dev branch
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Score
3
/10
Last Scanned on 2025-02-10
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More