node/fs

Source:

Methods

(static) readFileSyncFromUrl(url, relativePath, optionsopt) → {Buffer|String}

Description:
  • Reads a file synchronously relative to a URL's directory.

Source:
Example
const text = readFileSyncFromUrl(import.meta.url, "text-file.txt", "utf8");
Parameters:
Name Type Attributes Description
url String

The URL representing the module's location (e.g., import.meta.url).

relativePath String

The relative path to the file.

options object | String <optional>

The options to pass to readFileSync.

Throws:
  • If url or relativePath is not a string.

    Type
    TypeError
  • If there is an error reading the file.

    Type
    Error
Returns:

The file contents.

Type
Buffer | String