Tsallaka zuwa abun ciki
Justice Tech School

Checking Files

fs.existsSync tests a path. Prefer try catch around the real operation.

Example
const fs = require("fs");
console.log(fs.existsSync("/tmp"), fs.existsSync("/no/such/path"));
try { fs.readFileSync("/no/such/file"); }
catch (e) { console.log(e.code); }

Result

true false
ENOENT

Exercise

Error code for missing.

e.code === ""

Quiz Test

What is ENOENT?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.