Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

require-ancestors

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

require-ancestors

Returns the chain of JavaScript files used to require a given Node module - i.e. its ancestors

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
9.2K
decreased by-2.74%
Maintainers
1
Weekly downloads
 
Created
Source

require-ancestors

Returns the chain of JavaScript files used to require a given Node module - i.e. its ancestors.

Build status js-standard-style

Installation

npm install require-ancestors --save

Usage

Consider the following files:

file1.js

const ancestors = require('require-ancestors')

exports.static = ancestors(module)
exports.dynamic = function () {
  return ancestors(module)
}

file2.js

module.exports = require('./file1')

file3.js

module.exports = require('./file2')

file4.js

const file2 = require('./file2')
const file3 = require('./file3')

console.log(file3.static)
console.log(file2.static)
console.log(file3.dynamic())
console.log(file2.dynamic())

Now consider that we run file4.js using node file4.js.

The output from all 4 console.log statements will be identical: ['/full/path/file2.js', '/full/path/file4.js']. This is because ancestors(module) always will return the filenames in order based on the first time the module indicated by the module object was required.

API

arr = ancestors(module)

Arguments:

  • module - This should be the module object whos module you wish to get the chain of ancestors for. The module object is provided by Node core and is available to all modules

Returns an array of filenames used to require the given module. The filenames are sorted in the order they where originally required with the closest ancestor at index 0.

License

MIT

Keywords

FAQs

Package last updated on 20 Feb 2018

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

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc