Skip to content

ensureFile ​

Ensures a file exists.

Example ​

ts
import { 
SF
} from "@duplojs/server-utils";
import {
E
} from "@duplojs/utils";
const
result
= await
SF
.
ensureFile
("/tmp/empty.txt");
// result: E.Ok | SF.FileSystemLeft<"ensure-file"> if (
E
.
isRight
(
result
)) {
// if the file already exists, nothing happens (create if not exist) }

Syntax ​

typescript
function ensureFile(
  path: string
): Promise<FileSystemLeft<"ensure-file"> | E.Ok>

Parameters ​

  • path : path of the file.

Return value ​

  • E.Ok : if the file exists or was created.
  • FileSystemLeft<"ensure-file"> : if the operation fails.

See also ​

Released under the MIT license.