javascript - Reading local file from absolute path in node fs module -


i trying read file local system using node js 'fs' module. reason, 'fs' module not working when pass absolute path.

code:

let filepath = "/home/mysystem/dev/myproject/sayhello.txt"; let newfile=fs.readfilesync('file://'+filepath); 

the code throwing error as:

uncaught error: enoent: no such file or directory, open 'file:///home/mysystem/dev/myproject/sayhello.txt' 

but can open file browser window using same path. fs module working if pass relative path. using inside app built using electron framework.

in nodejs don't have use file protocol reading files.

you can rid of "file://" part , try read filepath directly

let filepath = "/home/mysystem/dev/myproject/sayhello.txt"; let newfile = fs.readfilesync(filepath); 

Comments