"Node. js" Global variables, common tools, file systems

Source: Internet
Author: User

Learning Links: http://www.runoob.com/nodejs/nodejs-global-object.html

In JavaScript, the window is usually a global object, while the global object in node. JS is global, and all global variables (except the global itself) are properties of the global object .

Global objects and global variables

Note: always use var to define variables to avoid introducing global variables, because global variables pollute namespaces and increase the risk of code coupling.

__filename

__dirname

SetTimeout (CB, MS)

Cleartimeout (t)

SetInterval (CB, MS)

Console

Process

Common tools

Util.inherits

Util.inspect

Util.isarray (object)

Util.isregexp (object)

Util.isdate (object)

Util.iserror (object)

File system

The methods in the node. JS File System (FS module) module have asynchronous and synchronous versions, such as functions that read the contents of the file with asynchronous Fs.readfile () and synchronous Fs.readfilesync ().

The last parameter of the Async method function is a callback function, and the first parameter of the callback function contains the error message (ERR).

Open File

The following is the syntax format for opening files in asynchronous mode:

Fs.open (path, flags[, mode], callback)

Get file information

Fs.stat (Path, callback)

Write file

Fs.writefile (file, data[, Options], callback)

Read file

Fs.read (fd, buffer, offset, length, position, callback)

Close File

Fs.close (FD, callback)

Intercepting files

Fs.ftruncate (FD, Len, callback)

deleting files

Fs.unlink (Path, callback)

Create a Directory

Fs.mkdir (path[, mode], callback)

Read Directory

Fs.readdir (Path, callback)

Delete Directory

Fs.rmdir (Path, callback)

"Node. js" Global variables, common tools, file systems

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.