Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Still saying fs.readdir is not a function #99

Open
lowenfas opened this issue May 21, 2023 · 1 comment
Open

Still saying fs.readdir is not a function #99

lowenfas opened this issue May 21, 2023 · 1 comment

Comments

@lowenfas
Copy link

I'm fairly new to these modules and NPMs but I've been getting along okay until now, this module seems like it's exactly what I need to fix my TypeError: fs.readdir is not a function. The problem is brfs isn't doing anything and the description/examples are not helping me at all.

How the hell am I supposed to use this module?

The only other thing I can say is that I did install brfs, it is in my dependencies alongside browserify, and the command I use in terminal to output my project is "browserify -t brfs main.js > bundle.js"
Below is my code, I tried some other lines even closer to the examples given but they also did not work, just gave me more errors. What am I missing? Thanks in advance.

const path = require('path'); const fs = require('fs'); // READS ALL FILES IN VIDEO FOLDER // //joining path of directory const directoryPath = path.join(__dirname, './Videos'); //passsing directoryPath and callback function fs.readdir(directoryPath, function (err, files) { //handling error if (err) { return console.log('Unable to scan directory: ' + err); } //listing all files using forEach files.forEach(function (file) { // Do whatever you want to do with the file console.log(file); }); });

@goto-bus-stop
Copy link
Member

generally fs cannot be used in browsers or adequately transformed beforehand (as accessing the user's filesystem from a browser is impossible). brfs only supports specific patterns that are common in npm modules, so calls to fs.readFile() with constant parameters. it's kinda the equivalent of "importing" a file as a string/arraybuffer. brfs can't access runtime values so it can't transform things like fs.readFile(someDynamicValue). fs.readdir is not supported because the other restrictions in brfs make it useless. hopefully that explains the limitations at least!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants