Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
parent-module
Advanced tools
Package description
The parent-module npm package allows you to find and require the parent module of a current module, which is useful in situations where you need to interact with or modify the behavior of the module that required your module. This can be particularly useful for plugins or modules that extend or modify the functionality of other modules.
Find and require the parent module
This feature allows you to find and require the parent module of the current module. The code sample demonstrates how to require the parent-module package and then use it to get the parent module. The 'parent' variable will contain the module object of the parent, and you can access properties such as 'filename' to get the file name of the parent module.
const parentModule = require('parent-module');
const parent = parentModule();
console.log(parent.filename);
The caller package allows you to get the file path of the caller function. It is similar to parent-module in that it helps you identify the calling module, but it focuses on the function call stack rather than the module hierarchy.
The caller-path package is similar to caller, providing the path of the caller function. It is a more focused tool compared to parent-module, which provides the entire parent module object.
This package is used to always get the main entry point file path of a module, regardless of the environment (e.g., when using a module bundler). It differs from parent-module by focusing on the entry point file rather than the immediate parent module.
Readme
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.
$ npm install --save parent-module
// 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();
By default, it will return the path of the immediate parent.
Type: string
Default: __filename
Filepath of the module of which to get the parent path.
Useful if you want it to work multiple module levels down.
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', ...}
MIT © Sindre Sorhus
FAQs
Get the path of the parent module
The npm package parent-module receives a total of 28,588,387 weekly downloads. As such, parent-module popularity was classified as popular.
We found that parent-module demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.