Home > Web Front-end > JS Tutorial > Instructions for using the fs.appendFileSync method in node.js_node.js

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

WBOY
Release: 2016-05-16 16:25:57
Original
2113 people have browsed it

Method description:

The function of this method is similar to fs.appendFile(). The only difference is that this method uses synchronous operation, while fs.appendFile uses asynchronous operation.

Grammar:

Copy code The code is as follows:

fs.appendFileSync(filename, data, [options])

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

Receive 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 code The 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);
};
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