Instructions for the fs.openSync method in node.js


method description:

fs.open ().

syntax:

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

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

receive parameters:

path         file path

flags         can be the following values

'r' -    Open the file in read mode.
'r+' -  Open the file in read/write mode.
'rs' -  Open and read the file in synchronous mode. Instructs the operating system to ignore the local file system cache.
'rs+' -  Open and read synchronously   and   Write to a file.
 
'w' -  Open the file in read mode and create it if it does not exist
'wx' -  and  ' w '  model 1 Returns failure if the file exists
'w+' -  Open the file in read/write mode and create it if it does not exist
'wx+' -  and  ' w+ '  model 1 Returns failure if the file exists
 
'a' -  Open the file in append mode and create it if it does not exist
'ax' -  and  ' a '  model 1 Returns failure if the file exists
'a+' -  Open the file in read append mode and create it if it does not exist
'ax+' -  and  ' a+ '  model 1 Returns failure if the file exists
mode     Used to assign permissions to a file when it is created, by default 0666

source code:

fs.openSync = function(path, flags, mode) {
  mode = modeNum(mode, 438 /*=0666*/);
  nullCheck(path);
  return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
};