Returns the absolute file path of a module.
import.meta.url (ESM) or __filename (CJS)
import.meta.url
__filename
Absolute path to the provided module file.
This utility supports both:
The path MUST be explicitly provided. Automatic runtime detection is intentionally not performed to avoid incorrect module resolution.
If metaUrlOrPath is not provided.
metaUrlOrPath
const file = locateModuleFile(import.meta.url);console.log(file); Copy
const file = locateModuleFile(import.meta.url);console.log(file);
const file = locateModuleFile(__filename);console.log(file); Copy
const file = locateModuleFile(__filename);console.log(file);
Returns the absolute file path of a module.