In node, there are a number of core modules, each of which accomplishes some specific functions:
http: Implementing HTTP Service
FS: File system module, dedicated to handling file operations
NET: Network module, to realize the programming of network
Path: Processing the path
URL: handles the URL address.
Util: Tool module that provides some common tools
Common file Operations:
The main is to delete and change (CRUD Create read update delete)
(Operations after the underlying operation and encapsulation)
(1). read files
Use the encapsulated method:
ReadFile reading files
ReadFile, there are synchronous and asynchronous two (with Sync end is synchronous version, otherwise it is asynchronous version,
The difference between synchronous and asynchronous is two points:
The order of execution is different.
The data is obtained in a different way, using the return value of the function synchronously, and asynchronously using the data parameter in the callback function. )
ReadFile asynchronous Read,
Output As Start end file contents
In node. js, the callback function, the error-first callback .
If the Err object is provided in the callback function, the Err object must be the first parameter of the function.
If there is an error, err is an object that contains an error message.
If there is no error, err is null.
Readfilesync Synchronous Read
Output as start file content end
(2. Write file operation
There are two modes of writing a file:
N Cover Type WriteFile
N-Append AppendFile
(3). deleting files
Unlink/unlinksync
(4). Determine if the file exists
Exists
Determine if the file exists.
(5). Get File information
For any one file, there is usually some information (attributes)
Fs.stat (Path,callback)
Fs.statsync (PATH)
Nodejs File System