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

Instructions for using the fs.openSync method in node.js_node.js

WBOY
Release: 2016-05-16 16:26:11
Original
2034 people have browsed it

Method description:

Synchronized version of fs.open() .

Grammar:

Copy code The code is as follows:

fs.openSync(path, flags, [mode])

Since this method belongs to the fs module, the fs module needs to be introduced before use (var fs= require(“fs”) )

Receive parameters:

path File path

flags can be the following values

Copy code The code is as follows:

'r' - Open the file in read mode.
'r ' - Open the file in read-write mode.
'rs' - Open and read the file using synchronous mode. Instructs the operating system to ignore the local file system cache.
'rs ' - Open, read and write the file synchronously.

'w' - Open the file in read mode or create it if it does not exist
'wx' - same as ' w ' mode, returns failure if the file exists
'w ' - Open the file in read-write mode, create the file if it does not exist
'wx ' - same as ' w ' mode, returns failure if the file exists

'a' - Open the file in append mode, creating it if it does not exist
'ax' - same as ' a ' mode, returns failure if the file exists
'a ' - Open file in read-append mode, create if file does not exist
'ax ' - same as ' a ' mode, returns failure if the file exists
mode is used to set permissions for files when creating files. The default is 0666

Source code:

Copy code The code is as follows:

fs.openSync = function(path, flags, mode) {
mode = modeNum(mode, 438 /*=0666*/);
nullCheck(path);
Return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
};
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!