updateFile

It writes to an existing file. The whole content of the file will be overwritten by whatever is passed in the 'content' parameter.
The function will resolve the 'fileLocationAndName' if the updating is successful.
Parameter ListReturnsRejection Errors
  • fileLocationAndName: string
  • content: string
  • tuple: Array (optional)
Promise<string || Array>
Related FunctionsFunction Signature
function updateFile(fileLocationAndName, content[, tuple]): Promise<string || Array>
1 2 3 import { updateFile } from "puddy-m/lib/fileFunctions"; updateFile("./foo.txt", "Hello, World").then(console.log); // "./foo.txt"
1 2 3 4 5 6 7 8 import { updateFile } from "puddy-m/lib/fileFunctions"; updateFile("./foo.txt", "Hello, World", []) .then((tuple) => updateFile("./foo.txt", "Updated: Hello, World", tuple)) .then(([filePath1, filePath2]) => { console.log(filePath1); // ./foo.txt console.log(filePath2); // ./foo.txt });
1 2 3 4 5 6 7 8 9 import { updateFile } from "puddy-m/lib/fileFunctions"; // It also works with await. const f = async () => { const fileLocation = await updateFile("./foo.txt", "Hello, World"); console.log(fileLocation); //"./foo.txt" }; f();