-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
26 lines (24 loc) · 1.04 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
const fs = require('fs');
/**
* Logs/appends data into a file asynchronously.
* @async
* @function
* @param {string} path The path of the file to be appended
* @param {string} data Data to be appended to the file (automatically appended with a new-line)
* @param {(Object|string)} [options=utf8] fs.appendFile options or string representing encoding ('utf8' by default)
* @example log('log.txt', 'hello world');
*/
module.exports = async function(path, data, options='utf8') {
return await fs.promises.appendFile(path, data+'\n', options);
}
/**
* Logs/appends data into a file synchronously.
* @function
* @param {string} path The path of the file to be appended
* @param {string} data Data to be appended to the file (automatically appended with a new-line)
* @param {(Object|string)} [options=utf8] fs.appendFile options or string representing encoding ('utf8' by default)
* @example log.sync('log.txt', 'hello world');
*/
module.exports.sync = function(path, data, options='utf8') {
return fs.appendFileSync(path, data+'\n', options);
}