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.
caller-path
Advanced tools
The caller-path npm package is designed to help developers retrieve the path of the file that calls a function. This can be particularly useful for debugging, logging, and tracking the flow of a program, especially in complex applications where functions are called from multiple places.
Get caller file path
This feature allows developers to log or retrieve the path of the file that called a function. In the provided code, the function `whoCalled` uses `callerPath()` to print the path of the caller file.
const callerPath = require('caller-path');
function whoCalled() {
console.log(callerPath());
}
module.exports = whoCalled;
The 'callsites' package provides functionality to get the call sites (stack frames) of the V8 stack trace API, which can be used to find the path of the caller. It offers more detailed control over the stack trace compared to caller-path, allowing developers to access deeper insights into the call stack.
This package is used to extract a stack trace from within a running node.js application, similar to caller-path. It differs in that it provides a more comprehensive set of features for manipulating and analyzing the stack trace beyond just retrieving the caller's path.
Get the path of the caller function
npm install caller-path
// foo.js
import callerPath from 'caller-path';
export default function foo() {
console.log(callerPath());
//=> '/Users/sindresorhus/dev/unicorn/bar.js'
}
// bar.js
import foo from './foo.js';
foo();
If the caller's callsite object getFileName
was not defined for some reason, it will return undefined
.
Get the path of the caller function.
Type: number
Default: 0
The caller path depth, meaning how many levels we follow back on the stack trace.
For example:
// foo.js
import callerPath from 'caller-path';
export default function foo() {
console.log(callerPath());
//=> '/Users/sindresorhus/dev/unicorn/foobar.js'
console.log(callerPath({depth: 1}));
//=> '/Users/sindresorhus/dev/unicorn/bar.js'
console.log(callerPath({depth: 2}));
//=> '/Users/sindresorhus/dev/unicorn/foo.js'
}
// bar.js
import foo from './foo.js';
export default function bar() {
foo();
}
// foobar.js
import bar from './bar.js';
bar();
FAQs
Get the path of the caller function
The npm package caller-path receives a total of 5,132,087 weekly downloads. As such, caller-path popularity was classified as popular.
We found that caller-path 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.