10 examples of 'node check if file exists' in JavaScript

Every line of 'node check if file exists' 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
60function checkExists (file) {
61 try {
62 fs.statSync(file);
63 return true;
64 } catch (_) {
65 return false;
66 }
67}
39static exists(file) {
40 return fs.existsSync(file);
41}
20function exists(file) {
21 const found = fs.existsSync(file);
22
23 if (!found) {
24 console.warn(`WARNING: ${file} not found`);
25 }
26
27 return found;
28}
17export function fileExists(file: string) {
18 return fs.existsSync(file);
19}
1223function exists(file) {
1224 try {
1225 if (fs.statSync(file).isFile()) {
1226 return true;
1227 }
1228 } catch (e) {
1229 return false;
1230 }
1231}
500function exists(file) {
501 try {
502 if (fs.statSync(file).isFile()) {
503 return true;
504 }
505 } catch (e) {
506 return false;
507 }
508}
34static exists(file) {
35 try {
36 fs.accessSync(file, fs.F_OK);
37 return true;
38 } catch (e) {
39 return false;
40 }
41}
173isFile() {
174 return false
175}
65function exists(filename) {
66 try {
67 fs.statSync(filename);
68 return true;
69 } catch (x) {
70 return false;
71 }
72}
58export function exists(file) {
59 console.log('exits', file);
60 return new Promise((resolve, reject) => {
61 let timeout = getTimeout(1, 5);
62 setTimeout(
63 () => {
64 console.log('timeout', file, timeout);
65 resolve(file == 'b.js');
66 },
67 timeout
68 );
69 });
70};

Related snippets