1const fs = require('fs');
2
3fs.writeFile("/tmp/test", "Hey there!", function(err) {
4 if(err) {
5 return console.log(err);
6 }
7 console.log("The file was saved!");
8});
9
10// Or
11fs.writeFileSync('/tmp/test-sync', 'Hey there!');
1const { promises: Fs } = require('fs')
2
3async function exists (path) {
4 try {
5 await Fs.access(path)
6 return true
7 } catch {
8 return false
9 }
10}
11
12// Example:
13const Path = require('path')
14const path = Path.join(__dirname, "existing-file.txt")
15
16await exists(path)
17// true
18