Propolys Propolys - 29 days ago 4x
Node.js Question

Node.js FileSystem access returns ENOENT despite the file existing

I have a node.js function which uses fs.access to check if a file exists, is readable and writable:

function StackOverFlowFunction() {
try {
fs.accessSync(`file://${__dirname}/config/config.ini`, fs.constants.F_OK | fs.constants.R_OK | fs.constants.W_OK);
} catch (err) {

despite the file EXISTING,

{ Error: ENOENT: no such file or directory, access 'file:///home/callcenter1/BookGenerator/config/config.ini'
at Error (native)
at Object.fs.accessSync (fs.js:248:11)
at Object.fs.accessSync (ELECTRON_ASAR.js:420:27)
at getConfig (/home/callcenter1/BookGenerator/main.js:12:12)
at Object.<anonymous> (/home/callcenter1/BookGenerator/main.js:18:10)
at Module._compile (module.js:541:32)
at Object.Module._extensions..js (module.js:550:10)
at Module.load (module.js:458:32)
at tryModuleLoad (module.js:417:12)
at Function.Module._load (module.js:409:3)
errno: -2,
code: 'ENOENT',
syscall: 'access',
path: 'file:///home/callcenter1/BookGenerator/config/config.ini' }

I used the "Open Link" function from the Ubuntu terminal and it opened the file with gedit successfully.

What's the issue?

Edit 1:

I'm almost sure the path is right:

enter image description here


Use a proper filesystem path, without a scheme:

fs.accessSync(`${__dirname}/config/config.ini`, ...)