There are quite a few functions related to the system operation. Can be divided into two major categories first.
The class is asynchronous + callback. The class is synchronous.
In this case only the asynchronous collation, synchronous only need to add the function name after the sync
1. The first is a class of the most conventional read-write functions, function names and forms, should be originated in the C language.
Fs.open (file path, read/write ID, [file mode value, 666], callback function (err, file handle fd)); Fs.read (file handle FD, written by Buffer,offset,length,position, callback function (err, bytesread, buffer)); Fs.write (file handle FD, read Buffer,offset,length,position, callback function (Err,byteswritten,buffer)); Fs.close (file handle, callback function) fs.truncate (file handle, truncation length, callback function); Fs.fsync (file handle, callback function);
2. Read and write directly to the file, it is more convenient to use.
Fs.readfile (file name, encoding, callback function (Err,data)); Fs.writefile (file name, data, encoding, callback function (err)); Fs.appendfile (file name, data, encoding, callback function (err));
3. Other common file operations
Determine if the file exists fs.exists (file path, callback (presence)); Rename fs.rename (old filename, new file name, callback function); File owner Change fs.chown (filename, Uid,gid, callback function),/fs.fchown (file handle Fd,uid,gid, callback function),/fs.lchown (link path, Uid,gid, callback function) ; File permission change fs.chmod (filename, mode, callback function),/fs.fchmod (file handle, mode, callback function),/fs.lchmod (link path, mode, callback function ); File Information fs.stat (file path, callback function (Err.fs.Stats object)),/fs.fstat (file handle FD, callback function (Err.fs.Stats object)),/fs.lstat (link path, callback function ( Err.fs.Stats object)); File time fs.utimes (file path, access time, new time, callback function);/fs.futimes (file handle, access time, new time, callback function); Monitor file fs.watchfile (file name, [Options],listener_callback (Stats of current file, stats before change));
4. Directory Operations
Fs.mkdir (path, permission mode/777, callback function); Fs.rmdir (path, callback function); Fs.readdir (Path, callback function (Err,filenamearray));
5. Link file operations
Create a link fs.link (srcpath, Dstpath, [callback]) fs.symlink (destination, path, [type], [callback]) Read the link to the path fs.readlink (path, [Callback (ERR,LINKSTR)]) Fs.unlink (Path,[callback]);
Nodejs A concise summary of common functions of the file Operation module FS (Files System)