7 examples of 'write file sync' in JavaScript

Every line of 'write file sync' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
9function write(file) {
10 var dir = path.dirname(file.path);
11 if (!fs.existsSync(dir)) {
12 mkdirp.sync(dir);
13 }
14
15 fs.writeFileSync(file.path, file.contents, {
16 mode: file.stat ? file.stat.mode : null
17 });
18}
26function createFileSync (file) {
27 if (fs.existsSync(file)) return
28
29 var dir = path.dirname(file)
30 if (!fs.existsSync(dir)) {
31 mkdir.mkdirsSync(dir)
32 }
33
34 fs.writeFileSync(file, '')
35}
31function createFileSync (file) {
32 let stats
33 try {
34 stats = fs.statSync(file)
35 } catch (e) {}
36 if (stats && stats.isFile()) return
37
38 const dir = path.dirname(file)
39 if (!fs.existsSync(dir)) {
40 mkdir.mkdirsSync(dir)
41 }
42
43 fs.writeFileSync(file, '')
44}
17function write(content, file, callback) {
18 fs.writeFile(file, content, 'utf8', function (error) {
19 if (error) {
20 throw error;
21 }
22
23 callback();
24 });
25}
62public writeSync(filepath: string, contents: string): void {
63 fs.outputFileSync(filepath, contents);
64}
21TempIcon.prototype.writeSync = function writeSync () {
22 if (this.exists) {
23 throw new Error('already written')
24 } else {
25 fs.writeFileSync(this.path, this.data)
26 this.exists = true
27 }
28}
5function writeBuffer(writePath, file, cb) {
6 var opt = {
7 mode: file.stat.mode
8 };
9
10 fs.writeFile(writePath, file.contents, opt, cb);
11}

Related snippets