Skip to content

nsuite v2.2.1


nsuite / writeFileSafely

Function: writeFileSafely() ​

writeFileSafely(filePath, content, options?): Promise<void>

Defined in: UtilsFile.ts:218

Safely writes content to a file, creating parent directories if they don't exist.

Parameters ​

filePath ​

string

The path to the file to be written.

content ​

string | Buffer<ArrayBufferLike> | DataView<ArrayBufferLike> | Uint8Array<ArrayBufferLike>

The content to write to the file.

options? ​

WriteFileOptions

Optional settings for the write operation.

Returns ​

Promise<void>

  • A promise that resolves when the file has been written.

Example ​

ts
import { writeFileSafely } from "nsuite";
await writeFileSafely("./logs/error.log", "Error message", { encoding: "utf8" });

Released under the Apache-2.0 License.