Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
parent-module
Advanced tools
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.
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 parent-module
// bar.js
import parentModule from 'parent-module';
export default function bar() {
console.log(parentModule());
//=> '/Users/sindresorhus/dev/unicorn/foo.js'
};
// foo.js
import bar from './bar.js';
bar();
By default, it will return the path of the immediate parent.
Type: string
Default: __filename
The file path 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.
import path from 'node:path';
import {readPackageUpSync} from 'read-pkg-up';
import parentModule from 'parent-module';
console.log(readPackageUpSync({cwd: path.dirname(parentModule())}).pkg);
//=> {name: 'chalk', version: '1.0.0', …}
FAQs
Get the path of the parent module
The npm package parent-module receives a total of 39,062,909 weekly downloads. As such, parent-module popularity was classified as popular.
We found that parent-module demonstrated a not healthy version release cadence and project activity because the last version was released 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
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.