Nodejs File System

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.