-
Notifications
You must be signed in to change notification settings - Fork 3
/
helpers.js
39 lines (35 loc) · 884 Bytes
/
helpers.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
27
28
29
30
31
32
33
34
35
36
37
38
const fs = require('fs');
function readFile(filePath) {
return new Promise((resolve, reject) => {
fs.readFile(filePath, (err, data) => {
if (err) {
reject(err);
} else {
resolve(data);
}
});
});
}
function writeFile(filePath, data) {
return new Promise((resolve, reject) => {
fs.writeFile(filePath, data, (err) => {
if (err) {
reject(err);
} else {
resolve();
}
});
});
}
function checkFileExists(filePath) {
return new Promise((resolve, reject) => {
fs.access(filePath, (err) => {
if (err) {
resolve(false);
} else {
resolve(true);
}
});
});
}
module.exports = { readFile, writeFile, checkFileExists };