
Company News
Socket Named Top Sales Organization by RepVue
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.
require-ancestors
Advanced tools
Returns the chain of JavaScript files used to require a given Node module - i.e. its ancestors
Returns the chain of JavaScript files used to require a given Node module - i.e. its ancestors.
npm install require-ancestors --save
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.
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 modulesReturns 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.
MIT
FAQs
Returns the chain of JavaScript files used to require a given Node module - i.e. its ancestors
We found that require-ancestors 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.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.