How to use the exists function from fs-extra
Find comprehensive JavaScript fs-extra.exists code examples handpicked from public code repositorys.
286 287 288 289 290 291 292 293 294 295
}) describe('postTemplatesInstallHandler', () => { describe('chosen url success', () => { beforeEach(() => { fse.exists.mockResolvedValue(false) }) it('where chosen url starts with a forward slash', async () => { req.body['chosen-url'] = chosenUrl
+ 5 other calls in file
143 144 145 146 147 148 149 150 151 152 153
url: '/' } ] async function readFileIfExists (path) { if (await fse.exists(path)) { return await fse.readFile(path, 'utf8') } }
+ 5 other calls in file
GitHub: play-co/native-android
32 33 34 35 36 37 38 39 40 41
var existsAsync = function (filename) { return new Promise(function (resolve) { if (!filename) { return resolve(false); } fs.exists(filename, function (exists) { resolve(exists); }); }); };
GitHub: data-fair/data-fair
681 682 683 684 685 686 687 688 689 690
dataset.id = baseId + i dataset.title = baseTitle + ' ' + i } // better to check file as well as db entry in case of file currently uploading dbExists = await db.collection('datasets').countDocuments({ id: dataset.id }) fileExists = await fs.exists(datasetUtils.dir(dataset)) i += 1 } while (dbExists || fileExists) if (draft) {
GitHub: LibreTexts/Libretext
1764 1765 1766 1767 1768 1769 1770 1771 1772 1773
failed = true; } // Publication covers try { if (!failed && await fs.exists(`./PDF/Letter/Finished/${zipFilename}/Publication/Content.pdf`)) { let dataBuffer = await fs.readFile(`./PDF/Letter/Finished/${zipFilename}/Publication/Content.pdf`); let lulu = await pdf(dataBuffer); numPages = lulu.numpages; console.log(`Got numpages${options.index ? ` [${options.index}]` : ''} ${lulu.numpages}`);
+ 17 other calls in file
GitHub: athombv/node-homey
2574 2575 2576 2577 2578 2579 2580 2581 2582 2583
]); if (!confirmCreate.confirm) return; // Check if the folder already exists, if not create it if (!await fse.exists(discoveryPath)) await mkdirAsync(discoveryPath); await writeFileAsync(path.join(discoveryPath, `${discoveryBase.title}.json`), JSON.stringify(discoveryJson, false, 2)); Log(colors.green(`✓ Discovery strategy created in \`${discoveryPath}\``));
+ 15 other calls in file
GitHub: muhamed-didovic/eddown
207 208 209 210 211 212 213 214 215 216
*/ async getCourseForDownload(page, link, { all }) { //this is student available API endpoint //https://www.educative.io/api/reader/github-student-pack //let's check if we can find this course in our courses if (!all && await fs.exists(path.resolve(__dirname, '../json/search-courses.json'))) { console.log('LOAD COURSE FROM LOCAL FILE'); const c = require(path.resolve(__dirname, '../json/search-courses.json')) const foundCourse = c.find(({ url }) => link.includes(url)) if (foundCourse) {
+ 19 other calls in file
GitHub: muhamed-didovic/eddown
29 30 31 32 33 34 35 36 37 38 39 40
}) module.exports = class Crawler { static async getCourses(searchFromLocalFile) { if (searchFromLocalFile && await fs.exists(path.resolve(__dirname, '../json/search-courses.json'))) { console.log('LOAD FROM LOCAL SEARCH FILE'); const courses = require(path.resolve(path.resolve(__dirname, '../json/search-courses.json'))) return courses.map(c => ({ ...c,
+ 11 other calls in file
GitHub: mifi/lossless-cut
1318 1319 1320 1321 1322 1323 1324 1325 1326 1327
// then try to open project from source file dir const sameDirEdlFilePath = getEdlFilePath(fp); // MAS only allows fs.stat (fs-extra.exists) if we don't have access to input dir yet, so check first if the file exists, // so we don't need to annoy the user by asking for permission if the project file doesn't exist if (await exists(sameDirEdlFilePath)) { // Ok, the file exists. now we have to ask the user, because we need to read that file await ensureAccessToSourceDir(fp); // Ok, we got access from the user (or already have access), now read the project file await loadEdlFile({ path: sameDirEdlFilePath, type: 'llc' });
+ 11 other calls in file
GitHub: muhamed-didovic/eddown
172 173 174 175 176 177 178 179 180 181
async getCourseForDownload(page, link, { all }) { //this is student available API endpoint //https://www.educative.io/api/reader/github-student-pack //let's check if we can find this course in our courses if (!all && await fs.exists(path.resolve(process.cwd(), 'json/search-courses.json'))) { console.log('LOAD COURSE FROM LOCAL FILE'); const c = require(path.resolve(process.cwd(), 'json/search-courses.json')) const foundCourse = c.find(({ url }) => link.includes(url)) if (foundCourse) {
+ 19 other calls in file
GitHub: hzcool/nflsoj
1291 1292 1293 1294 1295 1296 1297 1298 1299 1300
resolve(stdout) }) }); judge_result = JSON.parse(judge_result.replace(/\n/g,"\\\\n")) if(await fs.exists(output_path)) { judge_result.output = await new Promise((resolve, reject) => { fs.open(output_path, 'r', function(status, fd) { if(status) { resolve(null)
+ 4 other calls in file
GitHub: Cloud-V/Backend
891 892 893 894 895 896 897 898 899 900
return FileManager.writeTempRepoModules( repo, function (err, tempPath, files, reverseMap) { if (err) { if (typeof tempPath === "string") { fs.exists(tempPath, function (exists) { if (exists) { return rmdir(tempPath, function (err) { if (err) { return console.error(err);
+ 9 other calls in file
GitHub: muhamed-didovic/eddown
29 30 31 32 33 34 35 36 37 38 39 40
}) module.exports = class Crawler { static async getCourses(searchFromLocalFile) { if (searchFromLocalFile && await fs.exists(path.join(__dirname, '../json/search-courses.json'))) { console.log('LOAD FROM LOCAL SEARCH FILE'); const courses = require(path.join(__dirname, '../json/search-courses.json')) return courses.map(c => ({ ...c,
+ 19 other calls in file
GitHub: stevekeol/DApp-Hangzhou
367 368 369 370 371 372 373 374 375 376 377
} exports.createFile = function (distPath, fileName, text, cb, noOutput) { if (!text || !distPath || !fileName) return let self = this fs.exists(distPath, function (exists) { if (!exists) { self.mkdirs(distPath) } fs.writeFile(path.join(distPath, fileName), text, function (err) {
7853 7854 7855 7856 7857 7858 7859 7860 7861 7862 7863
exports.exists = function (filename, callback) { if (typeof callback === 'function') { return fs.exists(filename, callback) } return new Promise(resolve => { return fs.exists(filename, resolve) }) } // fs.read() & fs.write need special treatment due to multiple callback args
+ 26 other calls in file
24 25 26 27 28 29 30 31 32
console.warn('No path given. Using default options'); return defaultOptions; } const pathToOpen = path.resolve(optionsFilepath); if (!(await fs.exists(pathToOpen))) { console.warn('Path given does not exists. Using default options'); return defaultOptions; }
+ 6 other calls in file
106 107 108 109 110 111 112 113 114 115 116 117
}; async function loadGitHubUsernameCache() { const path = `${__dirname}/github_username_cache.json`; if (await fs.exists(path)) { const jsonString = await fs.readFile(path); return JSON.parse(jsonString); }
+ 539 other calls in file
67 68 69 70 71 72 73 74 75 76
* @returns {Object} - The template config object */ async function checkTemplateRootStructure(templatePath) { // Make sure the root of the repo has a template.json file const templateJsonPath = path.join(templatePath, 'template.json'); const templateJsonExists = await fse.exists(templateJsonPath); if (!templateJsonExists) { throw new Error(`A template must have a ${chalk.green('template.json')} root file`); } const templateJsonStat = await fse.stat(templateJsonPath);
GitHub: TrinhDangNam/Arduino
440 441 442 443 444 445 446 447 448 449
} var completeStatus = function(fetchError) { var promises = [ gitTools.getStatus(self.path), fs.exists(fspath.join(self.path,".git","MERGE_HEAD")) ]; return when.all(promises).then(function(results) { var result = results[0]; if (results[1]) {
GitHub: bunchtogether/blend2
179 180 181 182 183 184 185 186 187 188 189
data.toString('utf8').trim().split('\n').forEach((line) => processLogger.info(line)); }); }; const getThumbnail = async (streamUrl , thumbnailPath ) => { let exists = await fs.exists(thumbnailPath); if (exists) { const stats = await fs.stat(thumbnailPath); if (new Date() - new Date(stats.ctime) < 86400000) { return;
+ 29 other calls in file
fs-extra.readFileSync is the most popular function in fs-extra (9724 examples)