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
1
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

caller

@substack's caller.js as a module


Version published
Maintainers
1
Created

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

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 12 Sep 2014

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