You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 7-8.RSVP
Socket
Socket
Sign inDemoInstall

caller

Package Overview
Dependencies
Maintainers
2
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

caller

@substack's caller.js as a module


Version published
Weekly downloads
185K
increased by2.5%
Maintainers
2
Install size
4.63 kB
Created
Weekly downloads
 

Package description

What is caller?

The 'caller' npm package is used to identify the calling function or module in a Node.js application. It helps in debugging, logging, and tracing the flow of execution by providing information about the caller of a function.

What are caller's main functionalities?

Get the calling function

This feature allows you to get the file path of the calling function. In the example, 'caller()' is used inside 'exampleFunction' to log the file path of 'anotherFunction' which called 'exampleFunction'.

const caller = require('caller');

function exampleFunction() {
  console.log('Caller:', caller());
}

function anotherFunction() {
  exampleFunction();
}

anotherFunction();

Get the calling module

This feature allows you to get the file path of the calling module. In the example, 'caller()' is used inside 'exampleFunction' to log the file path of the module that required 'exampleFunction'.

const caller = require('caller');

module.exports = function exampleFunction() {
  console.log('Caller module:', caller());
};

const exampleFunction = require('./exampleFunction');

exampleFunction();

Other packages similar to caller

Changelog

Source

v1.1.0 (March 9, 2022)

  • fix: handle case where Error class is wrapped (#10)

Readme

Source
caller

Figure out your caller (thanks to @substack).

Initialization Time Caller
// foo.js

var bar = require('bar');
// bar.js

var caller = require('caller');
console.log(caller()); // `/path/to/foo.js`
Runtime Caller
// foo.js

var bar = require('bar');
bar.doWork();
// bar.js

var caller = require('caller');

exports.doWork = function () {
    console.log(caller());  // `/path/to/foo.js`
};

Depth

Caller also accepts a depth argument for tracing back further (defaults to 1).

// foo.js

var bar = require('bar');
bar.doWork();
// bar.js

var baz = require('baz');

exports.doWork = function () {
    baz.doWork();
};
// baz.js

var caller = require('caller');

exports.doWork = function () {
    console.log(caller(2));  // `/path/to/foo.js`
};

Keywords

FAQs

Package last updated on 10 Mar 2022

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc