Skip to content Skip to sidebar Skip to footer

Fs.readdir Is Not Working When I Try To Read A Folder

I am trying to read the files from a folder 'data' and the code below should normally work, but I am not able to understand why I am getting this error: Uncaught TypeError: _fs.rea

Solution 1:

I am answering my own question, in case it helps some others like me, who are moving from frontend coding to understanding node.js.

It's difficult to grasp that some modules are just not meant for browsers and fs is one them and when you try to use 'require' that's another roadblock.. so if, like me, you are here because you tried to use fs in your javascript linked to your html to read something from your local machine or server and expected it to show up on the browser, it won't work.

It's a bit frustrating but once you get your head around it, it makes sense. So although this might not be the answer you looked for, I thought I'd just share this so that you don't waste more time, trying to make it work.

Getting to understand node.js and how to use fs on node.js would be better use of time..:-)..

Post a Comment for "Fs.readdir Is Not Working When I Try To Read A Folder"