Opens a file stream and stores it in a singleton for shared access. Creates the necessary directories and the file if they do not exist.

Thrown if the environment is not a Node.js server.

Thrown if a file stream for the given file path is already open.

Thrown if any unexpected error occurs during the opening of the file stream.

  • Parameters

    • filePath: string

      The path to the file where the stream will write.

    • Optionaloptions: {
          flushInterval?: number;
          minBufferSize?: number;
          mkDir?: boolean;
          sync?: boolean;
      }

      Optional configuration options for the file stream.

      • OptionalflushInterval?: number
      • OptionalminBufferSize?: number

        The minimum buffer size before writing to the file.

      • OptionalmkDir?: boolean

        Whether to create directories if they don't exist.

      • Optionalsync?: boolean

        Whether to synchronize writes to the file.

    Returns Promise<string>

    The key of the singleton object for the opened stream.