JS Utils Kit
    Preparing search index...

    Function resolveModuleRelative

    • Resolves a path relative to the provided module's directory.

      Parameters

      • relativePath: string

        Path relative to the module directory

      • metaUrlOrPath: string

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

      Returns string

      Absolute resolved path.

      Useful for loading internal assets such as:

      • .hbs templates
      • JSON files
      • SQL schemas
      • bundled static resources

      Unlike process.cwd(), this resolves relative to the module file location, making it safe for usage inside node_modules.

      If module path is not provided.

      const templatePath = resolveModuleRelative(
      "../templates/welcome.hbs",
      import.meta.url
      );
      const templatePath = resolveModuleRelative(
      "../templates/welcome.hbs",
      __filename
      );