Node Fs
Contents
Constants
Synchronous API
AccessSyunc
AppendFileSync
ChModSync
ChOwnSync
CopyFileSync
ExistsSync
LinkSync
MkDirSync
MkDTempSync
ReadDirSync
const fs = require("fs"); function readDirectory(directory) { let files = fs.readdirSync(directory); return files.sort((a,b) => a.localeCompare(b)); };
ReadFileSync
ReadLinkSync
RealPathSync
RenameSync
RmDirSync
RmSync
StatSync
SymLinkSync
UnlinkSync
UTimesSync
WriteFileSync
Callback API
Access
AppendFile
ChMod
ChOwn
CopyFile
Exists
Deprecated. Use stat or access instead.
Furthermore, do not try using this to check if a file exists before writing it. This will introduce a race condition.
const fs = require("fs"); exists(filename, (err) => { if (err) { console.log("file exists"); } });
Link
MkDir
MkDTemp
ReadDir
ReadFile
const fs = require("fs"); fs.readFile(filename, "utf8", (err, content) => { if (err) { console.log("cannot read file"); } else { console.log(content); } });
ReadLink
RealPath
Rename
RmDir
Rm
Stat
SymLink
Unlink
UnwatchFile
UTimes
WatchFile
WriteFile
fs.writeFile(filename, content, (err) => { if (err) { console.log("cannot write file"); } });