How to use the writeFileSync function from graceful-fs

Find comprehensive JavaScript graceful-fs.writeFileSync code examples handpicked from public code repositorys.

59
60
61
62
63
64
65
66
67
68
69
70
71


function writeFileSync(path, data, options) {
  if (!path) throw new TypeError('path is required!');


  fs.mkdirSync(dirname(path), { recursive: true });
  fs.writeFileSync(path, data, options);
}


function appendFile(path, data, options = {}) {
  if (!path) throw new TypeError('path is required!');
fork icon9
star icon48
watch icon0

+ 7 other calls in file

58
59
60
61
62
63
64
65
66
67
})

// wait a sec for those writes to go out.
setTimeout(function () {
  // write something else to the target.
  fs.writeFileSync(target, 'brutality!\n')

  // write some more stuff.
  streams.forEach(function (stream, i) {
    stream.write('second write ' + i + '\n')
fork icon1
star icon1
watch icon0

41
42
43
44
45
46
47
48
49
50
TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'move')

fse.emptyDirSync(TEST_DIR)

// Create fixtures:
fs.writeFileSync(path.join(TEST_DIR, 'a-file'), 'sonic the hedgehog\n')
fs.mkdirSync(path.join(TEST_DIR, 'a-folder'))
fs.writeFileSync(path.join(TEST_DIR, 'a-folder/another-file'), 'tails\n')
fs.mkdirSync(path.join(TEST_DIR, 'a-folder/another-folder'))
fs.writeFileSync(path.join(TEST_DIR, 'a-folder/another-folder/file3'), 'knuckles\n')
fork icon802
star icon0
watch icon91

+ 7 other calls in file

8
9
10
11
12
13
14
15
16
17
let tmpfile = path.join('millis-test-sync' + Date.now().toString() + Math.random().toString().slice(2))
tmpfile = path.join(os.tmpdir(), tmpfile)

// 550 millis past UNIX epoch
const d = new Date(1435410243862)
fs.writeFileSync(tmpfile, 'https://github.com/jprichardson/node-fs-extra/pull/141')
const fd = fs.openSync(tmpfile, 'r+')
fs.futimesSync(fd, d, d)
fs.closeSync(fd)
return fs.statSync(tmpfile).mtime > 1435410243000
fork icon1
star icon0
watch icon0

103
104
105
106
107
108
109
110
111
112
113
114
    return Function('return this')();
  }
})();


var jestWriteFile =
  global[Symbol.for('jest-native-write-file')] || fs.writeFileSync;


var global = (function () {
  if (typeof globalThis !== 'undefined') {
    return globalThis;
fork icon0
star icon0
watch icon1