Use of fs. appendFileSync in node. js, fs. appendfile
Method description:
The function of this method is similar to fs. appendFile (). The only difference is that this method uses synchronous operations, while fs. appendFile uses asynchronous operations.
Syntax:
Copy codeThe Code is as follows:
Fs. appendFileSync (filename, data, [options])
Because this method belongs to the fs module, we need to introduce the fs module (var fs = require ("fs") before use "))
Receiving parameters:
1. filename {String}
2. data {String | Buffer}
3. options {Object}
Encoding {String | Null} default = 'utf8 ′
Mode {Number} default = 438 (aka 0666 in Octal)
Flag {String} default = 'A'
Source code:
Copy codeThe Code is as follows:
Fs. appendFileSync = function (path, data, options ){
If (! Options ){
Options = {encoding: 'utf8', mode: 438/* = 0666 */, flag: 'A '};
} Else if (util. isString (options )){
Options = {encoding: options, mode: 438, flag: 'A '};
} Else if (! Util. isObject (options )){
Throw new TypeError ('bad arguments ');
}
If (! Options. flag)
Options = util. _ extend ({flag: 'A'}, options );
Fs. writeFileSync (path, data, options );
};