Function writeJson

  • Parameters

    • filePath: string

      The path to the file where the JSON content will be written.

    • content: object

      The JSON content to be written to the file.

    Returns Promise<void>

    A Promise that resolves when the JSON content has been successfully written to the file.

    Throws

    If there is an error creating the parent directory, writing the file, or stringifying the JSON content. - The writeJson function is an asynchronous function that writes JSON content to a file at the specified file path. - It creates the parent directory if it doesn't exist, stringifies the JSON content, and writes it to the file.

    Example

    const filePath = "path/to/file.json";
    const content = { name: "John", age: 30 };
    writeJson(filePath, content)
    .then(() => {
    console.log("JSON content written to file successfully");
    })
    .catch((error) => {
    console.error("Failed to write JSON to file:", error);
    });

Generated using TypeDoc