import.meta.url


  • <string> 模块的绝对 file: URL。

    ¥<string> The absolute file: URL of the module.

这与提供当前模块文件 URL 的浏览器中的定义完全相同。

¥This is defined exactly the same as it is in browsers providing the URL of the current module file.

这可以启用有用的模式,例如相对文件加载

¥This enables useful patterns such as relative file loading:

import { readFileSync } from 'node:fs';
const buffer = readFileSync(new URL('./data.proto', import.meta.url));