Socket
Socket
Sign inDemoInstall

callsite

Package Overview
Dependencies
0
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    callsite

access to v8's CallSites


Version published
Weekly downloads
2.5M
increased by0.75%
Maintainers
1
Install size
2.16 kB
Created
Weekly downloads
 

Package description

What is callsite?

The callsite npm package allows developers to access the call stack of V8 engines in Node.js applications. It provides a way to inspect and manipulate the call stack, which can be useful for debugging, logging, and tracking the flow of an application. The package offers a straightforward API to retrieve an array of call sites (stack frames), enabling developers to programmatically explore and utilize call stack information.

What are callsite's main functionalities?

Accessing the call stack

This feature allows developers to access the current call stack. The code sample demonstrates how to use the callsite package to retrieve the call stack within a function and then print the file name of the caller function.

const callsite = require('callsite');

function sampleFunction() {
  const stack = callsite();
  const requester = stack[1].getFileName();
  console.log(`Called by ${requester}`);
}

sampleFunction();

Other packages similar to callsite

Readme

Source

callstack

Access to v8's "raw" CallSites.

Installation

$ npm install callsite

Example

var stack = require('callsite');

foo();

function foo() {
  bar();
}

function bar() {
  baz();
}

function baz() {
  console.log();
  stack().forEach(function(site){
    console.log('  \033[36m%s\033[90m in %s:%d\033[0m'
      , site.getFunctionName() || 'anonymous'
      , site.getFileName()
      , site.getLineNumber());
  });
  console.log();
}

Why?

Because you can do weird, stupid, clever, wacky things such as:

  • better-assert

License

MIT

Keywords

FAQs

Last updated on 24 Jan 2013

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc