Home > Web Front-end > JS Tutorial > body text

A concise summary of common functions of nodejs file operation module FS (File System)_node.js

WBOY
Release: 2016-05-16 16:46:12
Original
1225 people have browsed it

There are many functions related to software system operations. First of all, it can be divided into two categories.

One type is asynchronous callback. One type is synchronous.

Only the asynchronous ones are sorted here. For the synchronous ones, just add Sync after the function name

1. The first is the most common type of reading and writing functions. The function name and form should originate from the C language.

Copy code The code is as follows:

fs.open(file path , read and write identification, [file mode value, 666], callback function (err, file handle fd));        
fs.read(file handle fd, written buffer, offset, length, position, callback function ( err, bytesRead, buffer)); " " Handle, callback function)                                                                                                                                                            

2. It is more convenient to read and write files directly.


Copy code

3. Other common file operations





Copy code
The code is as follows:
Determine whether the file exists fs.exists(file path, callback (whether it exists)); Rename fs.rename(old File name, new file name, callback function); File owner change Function);/fs.lchown (link path, uid, gid, callback function); , 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)); Path, access time, new time, callback function);/fs.futimes(file handle, access time, new time, callback function); (Stats of the current file, stats before change));                                                                                      


4. Directory operations






Copy code


The code is as follows:


fs.mkdir(path, permission mode/777, callback function);
fs.rmdir(path, callback function); fs.readdir(path, callback function (err, fileNameArray));


5. Link file operation

The code is as follows:


Create a link
fs.link(srcpath, dstpath, [callback])
fs.symlink(destination, path, [type], [callback])

The path pointed by the read link fs.readlink(path, [callback(err,linkstr)]) fs.unlink(path,[callback]);

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template