How to use the default function from fs

Find comprehensive JavaScript fs.default code examples handpicked from public code repositorys.

94
95
96
97
98
99
100
101
102
103
}
catch (error) {
    console.log(error);
}
// Iterate through the folder and its subfolders
const items = fs_1.default.readdirSync(folderPath, { withFileTypes: true });
for (const item of items) {
    const itemPath = path_1.default.join(folderPath, item.name);
    if (item.isDirectory()) {
        // Create the folder if it doesn't exist
fork icon1
star icon3
watch icon1

+ 3 other calls in file

23
24
25
26
27
28
29
30
31
32
(_b = y.stderr) === null || _b === void 0 ? void 0 : _b.on("data", function (s) { out += s; if (echo)
    console.log("" + s); });
processes[key_and_name].on("close", function (code, signal) {
    if (code == 0)
        r(undefined);
    fs_1.default.writeFileSync("".concat(key_and_name, ".log"), out);
    console.log("== ".concat(key_and_name, " exited with : ").concat(code, " "));
    if (!echo)
        console.log(out);
    if (code == 0)
fork icon0
star icon1
watch icon2

+ 11 other calls in file

144
145
146
147
148
149
150
151
152
153
    const collections = yield (0, model_services_1.findManyService)(collection_model_1.default, { volumeTrade: { $ne: 0 }, collectionAddress: { $ne: process.env.BOARC_ADDRESS } }, "_id");
    const topCollection = {};
    yield Promise.all(collections.map((collection) => __awaiter(void 0, void 0, void 0, function* () {
        topCollection[collection._id] = yield getCollectionDetailService(collection._id);
    })));
    fs_1.default.writeFile("../../../public/topCollection.json", JSON.stringify(topCollection), "utf8", () => {
        console.log(`Update top collection successfully at ${new Date(Date.now())}`);
    });
    // express.static(path.join(__dirname, "../../public"))
}
fork icon0
star icon1
watch icon1

+ 2 other calls in file

180
181
182
183
184
185
186
187
188
189
            percent30Days: percentTrade30,
        };
    })));
    // userTrades.sort((a, b) => b.volumeTrade - a.volumeTrade);
    trd = userTrades.filter(data => data.volume30Days);
    fs_1.default.writeFile("./public/topTrader.json", JSON.stringify(trd), "utf8", () => {
        console.log(`Update top trader successfully at ${new Date(Date.now())}`);
    });
});
exports.topTraderAutoService = topTraderAutoService;
fork icon0
star icon1
watch icon1

+ 5 other calls in file

52
53
54
55
56
57
58
59
60
61
const { userAddress } = req.params;
let data = req.body;
data = (0, other_services_1.removeUndefinedOfObj)(data);
const user = yield (0, model_services_1.updateOneService)(user_model_1.default, { userAddress }, data);
if (data.email && (!user.confirmEmail || user.email !== data.email)) {
    let html = fs_1.default.readFileSync(`${default_constant_1.STATIC_FOLDER}/views/verificationEmail.html`, { encoding: "utf8" });
    let token = jsonwebtoken_1.default.sign({ userAddress }, "secret", { expiresIn: "10m" });
    token = encodeURIComponent(token);
    let host = "https://api.nftspacex.io/aptos";
    let link = `${host}/users/verify-email/${userAddress}/${token}`;
fork icon0
star icon1
watch icon1

+ 2 other calls in file

19
20
21
22
23
24
25
26
27
28
const history_services_1 = require("../services/history.services");
const other_services_1 = require("./other.services");
const fs_1 = __importDefault(require("fs"));
const getTopCollectionService = (sortBy = "volumeTrade", sortFrom, objectQuery = {}, pageSize, pageId, chainId) => __awaiter(void 0, void 0, void 0, function* () {
    objectQuery = (0, other_services_1.removeUndefinedOfObj)(objectQuery);
    const folder = fs_1.default.readdirSync("./public");
    if (!folder.includes("topCollection.json")) {
        fs_1.default.writeFile("./public/topCollection.json", "", "utf8", () => {
            console.log(`Update top collection successfully at ${new Date(Date.now())}`);
        });
fork icon0
star icon1
watch icon1

+ 11 other calls in file

43
44
45
46
47
48
49
50
51
52
const client_1 = require("@prisma/client");
exports.dbPath = electron_is_dev_1.default ? path_1.default.join(__dirname, "../prisma/dev.db") : path_1.default.join(electron_1.app.getPath("userData"), "database.db");
if (!electron_is_dev_1.default) {
    try {
        // database file does not exist, need to create
        fs_1.default.copyFileSync((0, path_1.join)(process.resourcesPath, "prisma/dev.db"), exports.dbPath, fs_1.default.constants.COPYFILE_EXCL);
        console.log("New database file created");
    }
    catch (err) {
        if (err.code != "EEXIST") {
fork icon0
star icon1
watch icon1

+ 3 other calls in file

35
36
37
38
39
40
41
42
43
44
fs_1.default.appendFile(`src/server/Migrations/create_c_${config_name}_table.ts`, Migration, function (err) {
    if (err)
        throw err;
    console.log(`Migration File C_${config_name} is created successfully.`);
});
fs_1.default.appendFile(`src/ts/frontend/components/C_${config_name}.ts`, content, function (err) {
    if (err)
        throw err;
    console.log(`Component C_${config_name} is created successfully.`);
});
fork icon0
star icon1
watch icon1

+ 3 other calls in file

49
50
51
52
53
54
55
56
57
58
spectral.setRuleset({ extends: [[asyncapiRulset_1.default, 'all']] });
const filePaths = core.getMultilineInput('files', { required: true });
//const filePaths = ['examples/asyncapi-02.yaml', 'examples/asyncapi-03.yaml'];
for (const filePath of filePaths) {
    console.log(`\nLinting "${filePath}"...\n`);
    const asyncApiFile = fs_1.default.readFileSync(filePath, 'utf8');
    const problemList = yield spectral.run(asyncApiFile);
    formatResult(problemList, errors, filePath);
}
if (errors.length) {
fork icon0
star icon0
watch icon1

52
53
54
55
56
57
58
59
60
61
    }
    return "0.69.1";
};
const onTmpFolder = async function (dest, callback) {
    const appPrefix = 'electron-to-nwjs';
    let tmpDir = fs_1.default.mkdtempSync(path_1.default.join(os_1.default.tmpdir(), appPrefix));
    console.log(`Temporary folder: ${tmpDir}`);
    try {
        await callback(tmpDir);
    }
fork icon0
star icon0
watch icon1

+ 14 other calls in file

25
26
27
28
29
30
31
32
33
34
    accessKeyId,
    secretAccessKey,
});
const uploadToS3 = (fileData) => __awaiter(void 0, void 0, void 0, function* () {
    try {
        const fileContent = fs_1.default.readFileSync(fileData.path);
        const params = {
            Bucket: bucketName,
            Key: fileData.originalname,
            Body: fileContent,
fork icon0
star icon0
watch icon1

34
35
36
37
38
39
40
41
42
43
    const error = new http_error_1.HttpError(messages_1.ERROR_UNDEFINED_ROUTE, enums_1.HTTP_RESPONSE_STATUS.Not_Found);
    throw error;
});
app.use((error, req, res, next) => {
    if (req.file) {
        fs_1.default.unlink(req.file.path, () => {
            console.log(error);
        });
    }
    if (res.headersSent) {
fork icon0
star icon0
watch icon1

364
365
366
367
368
369
370
371
372
373
  ctx.continue = true;
  return ctr;
}
const compression = (0, import_handleCompressType.default)(ctg.options.compression);
try {
  stream = import_fs.default.createReadStream(file);
  ctx.waiting = true;
  stream.pipe(compression);
  compression.pipe(res);
} catch (e) {
fork icon0
star icon0
watch icon1

+ 9 other calls in file

123
124
125
126
127
128
129
130
131
132
const stream = file.createWriteStream({
    resumable: false,
});
console.log("file ok");
var pathImg = "./src/image/" + fileGet.originalname;
fs_1.default.createReadStream(pathImg)
    .pipe(stream)
    .on("error", (error) => {
    console.error("Error uploading image:", error);
    return res.status(500).json({ message: "Upload file to firebase error!" });
fork icon0
star icon0
watch icon0

8
9
10
11
12
13
14
15
16
17
const wa_map_optimizer_1 = require("wa-map-optimizer");
const crypto_1 = __importDefault(require("crypto"));
const tiled_map_type_guard_1 = require("@workadventure/tiled-map-type-guard");
function getMaps(mapDirectory = ".") {
    let mapFiles = new Map();
    for (const file of fs_1.default.readdirSync(mapDirectory)) {
        const fullPath = mapDirectory + "/" + file;
        if (mapDirectory && fs_1.default.lstatSync(fullPath).isDirectory() && file !== "dist" && file !== "node_modules") {
            mapFiles = new Map([...mapFiles, ...getMaps(fullPath)]);
        }
fork icon0
star icon0
watch icon1

+ 6 other calls in file

3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
binary.data.length = stat.size - binary.data.offset;
source = `exports.__binary = ${JSON.stringify(binary)};\n${source}`;
let cmeta = Kawix.$binaryMetadata.get(filename);

if (cmeta !== null && cmeta !== void 0 && cmeta.fd) {
  _fs.default.closeSync(cmeta.fd);
} //console.info(filename, binary)


Kawix.$binaryMetadata.set(filename, binary);
fork icon0
star icon0
watch icon1

+ 127 other calls in file

43
44
45
46
47
48
49
50
51
52
app.get('/', (req, res) => {
    res.json({ message: 'Please Like the Video!' });
});
app.get('/csv', (req, res) => {
    const result = [];
    fs_1.default.createReadStream('./public/docs/eggs.csv')
        .pipe(csv_parser_1.default())
        .on('data', (data) => {
        result.push({
            date: data.DATE,
fork icon0
star icon0
watch icon1

136
137
138
139
140
141
142
143
144
145
const fileNameMatch = src.value.match(/(\w+\.\w+)$/g);
if (!fileNameMatch)
    return null;
const fileName = fileNameMatch[0];
const fileNameData = parseFileName(fileName);
const data = fs_1.default.readFileSync((0, utils_1.fpath)(config.basePath, src.value), 'utf-8');
return {
    name: fileNameData,
    data
};
fork icon0
star icon0
watch icon1

161
162
163
164
165
166
167
168
169
170
    // "UPDATE_COMPLETE",
    "UPDATE_ROLLBACK_COMPLETE",
    "UPDATE_ROLLBACK_FAILED"
];
let templateBody;
await fs_1.default.readFile(templateFilePath, { encoding: "utf-8" }, (err, data) => {
    if (err) {
        core.setFailed(`Unable to read template file ${templateFilePath}`);
    }
    else {
fork icon0
star icon0
watch icon0

30
31
32
33
34
35
36
37
38
39
});
try {
    const result = yield electron_1.dialog.showOpenDialog({ properties: ['openFile'] });
    if (!result.canceled && result.filePaths.length > 0) {
        const fileName = result.filePaths[0];
        const fileContent = fs_1.default.readFileSync(result.filePaths[0], 'utf-8');
        const current = { name: path_1.default.basename(fileName), content: fileContent };
        if (isSameFileOpen(current)) {
            (0, Local_1.Logger)({
                type: Local_1.ELogger.Warning,
fork icon0
star icon0
watch icon1