JS Utils Kit
    Preparing search index...

    Function locateModuleFile

    • Returns the absolute file path of a module.

      Parameters

      • metaUrlOrPath: string

        import.meta.url (ESM) or __filename (CJS)

      Returns string

      Absolute path to the provided module file.

      This utility supports both:

      • ESM → pass import.meta.url
      • CommonJS → pass __filename

      The path MUST be explicitly provided. Automatic runtime detection is intentionally not performed to avoid incorrect module resolution.

      If metaUrlOrPath is not provided.

      const file = locateModuleFile(import.meta.url);
      console.log(file);
      const file = locateModuleFile(__filename);
      console.log(file);