readFile
Description
Reads a file and resolves the content of the file.
Parameter List | Returns | Rejection Errors |
---|---|---|
| Promise<string || Array> | |
Related Functions | Function Signature | |
function readFile(fileLocation[, tuple]): Promise<string || Array> |
Examples
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();