0% found this document useful (0 votes)
32 views1 page

Fs Module Cheatsheet

Uploaded by

pranav. bandaram
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views1 page

Fs Module Cheatsheet

Uploaded by

pranav. bandaram
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Node.

js fs Module Cheat Sheet


Method Description Async Example (Callback)

fs.readFile() Read file contents fs.readFile("file.txt", "utf8", (err, data) => {...});
fs.readFileSync() Read file synchronously const data = fs.readFileSync("file.txt", "utf8");
fs.writeFile() Write to a file (overwrites) fs.writeFile("file.txt", "Hello", (err) => {...});
fs.writeFileSync() Write synchronously fs.writeFileSync("file.txt", "Hello");
fs.appendFile() Append to a file fs.appendFile("file.txt", " More", (err) => {...});
fs.unlink() Delete a file fs.unlink("file.txt", (err) => {...});
fs.existsSync() Check if file exists if (fs.existsSync("file.txt")) {...}
fs.mkdir() Create a directory fs.mkdir("myDir", (err) => {...});
fs.readdir() Read directory contents fs.readdir("myDir", (err, files) => {...});
fs.rename() Rename file/folder fs.rename("old.txt", "new.txt", (err) => {...});

You might also like