Type: Documentation-only

    A CommonJS module can access the first module that required it using module.parent. This feature is deprecated because it does not work consistently in the presence of ECMAScript modules and because it gives an inaccurate representation of the CommonJS module graph.

    Some modules use it to check if they are the entry point of the current process. Instead, it is recommended to compare require.main and module:

    1. if (require.main === module) {
    2. // Code section that will run only if current file is the entry point.
    3. }

    When looking for the CommonJS modules that have required the current one, require.cache and module.children can be used:

    1. const moduleParents = Object.values(require.cache)
    2. .filter((m) => m.children.includes(module));