openFileToWrite

Opens a file using the wx flag, which means that the file cannot exist. Although you can use this function standalone, this is to be meant to be used as a dependency of the writeFile function. Returns the file descriptor of the open file.
Parameter ListReturnsRejection Errors
  • fileLocationAndName: string
  • tuple: Array (optional)
Promise<number || Array>
Related FunctionsFunction Signature
function openFileToWrite(fileLocationAndName[, tuple]): Promise<string || Array>
1 2 3 4 5 import { openFileToWrite, writeFile } from "puddy-m/lib/fileFunctions"; // The steps below can be skipped by using the createFile function. // They are here only to illustrate how to use openFileToWrite helper function openFileToWrite("./foo.txt") // opens file .then(fileDescriptor=>writeFile(fileDescriptor, "Lorem Ipsum")) // writes content to file. The writeFile function closes the file.