How to use the createFileSync function from fs-extra

Find comprehensive JavaScript fs-extra.createFileSync code examples handpicked from public code repositorys.

fs-extra.createFileSync is a function in the fs-extra library that creates a new file synchronously if it does not already exist.

42
43
44
45
46
47
48
49
50
51
statsFile;
statsFileExist() {
    return fs.existsSync(this.statsFileLocation);
}
createStatsFile() {
    fs.createFileSync(this.statsFileLocation);
}
parseFileManagers(managers) {
    const files = managers;
    if (!files)
fork icon0
star icon0
watch icon1

+ 3 other calls in file

How does fs-extra.createFileSync work?

fs-extra.createFileSync is a function provided by the fs-extra library, which creates a new file synchronously and writes an empty data into it if the file does not already exist. If the file already exists, it will not modify its content and simply return. Internally, it uses the fs.openSync() and fs.closeSync() methods to open and close the file, and fs.futimesSync() to update the file's access and modification timestamps.

Ai Example

1
2
3
4
const fs = require("fs-extra");

// Create a new file named "example.txt" in the current directory
fs.createFileSync("example.txt");

This will create a new file named "example.txt" in the current directory. If the file already exists, it will not modify its contents.

function icon

fs-extra.readFileSync is the most popular function in fs-extra (9724 examples)