import.meta.url


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

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

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

import { readFileSync } from 'fs';
const buffer = readFileSync(new URL('./data.proto', import.meta.url));
  • <string> The absolute file: URL of the module.

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 'fs';
const buffer = readFileSync(new URL('./data.proto', import.meta.url));