puter.fs.read()


Reads data from a file.

Syntax

Code copied
puter.fs.read(path)

Parameters

path (String) (required)

Path of the file to read. If path is not absolute, it will be resolved relative to the app's root directory.

Return value

A Promise that will resolve to the contents of the file.

Examples

Read a file

Code copied
<html>
<body>
    <script src="https://js.puter.com/v2/"></script>
    <script>
        (async () => {
            // (1) Create a random text file
            let filename = puter.randName() + ".txt";
            await puter.fs.write(filename, "Hello world! I'm a file!");
            puter.print(`"${filename}" created<br>`);

            // (2) Read the file and print its contents
            let content = await puter.fs.read(filename);
            puter.print(`"${filename}" read (content: "${content}")<br>`);
        })();
    </script>
</body>
</html>