readFile

Reads a file and resolves the content of the file.
Parameter ListReturnsRejection Errors
  • fileLocation: string
  • tuple: Array (optional)
Promise<string || Array>
Related FunctionsFunction Signature
function readFile(fileLocation[, tuple]): Promise<string || Array>
1 2 3 4 import { readFile } from "puddy-m/lib/fileFunctions"; // Suppose you have a file called foo.txt and // its content is bar readFile("./foo.txt").then((fileContent) => console.log(fileContent)); // bar
1 2 3 4 5 6 7 8 9 10 11 import { readFile } from "puddy-m/lib/fileFunctions" // Suppose you have a file called foo.txt and // another one called bar.txt // In foo.txt you have fizz text // Whereas in bar.txt you have buzz text readFile("./parseJsonToObject.json", []) .then((tuple) => readFile("./readFile.json", tuple)) .then(([fileContent1, fileContent2]) => { console.log(fileContent1); // fizz console.log(fileContent2); // buzz });
1 2 3 4 5 6 7 8 import { readFile } from "puddy-m/lib/fileFunctions"; // It also works with await. const f = async () => { const fileContent = await readFile("./foo.txt"); console.log(fileContent); }; f();