-1

I have a folder structure which starts at my project Note that user.hash and user are MD5 hash

root/data/${user.hash}/

Now, what i need to do is read the files in side that directory using:

  var companies = fs.readdirSync(`../data/${user}/`);

I also tried

var BASE_FOLDER = path.resolve(__dirname, "..");

  var companies = fs.readdirSync(`${BASE_FOLDER}/data/${user}/`);

And in both cases i get the following error:

UnhandledPromiseRejectionWarning: Error: ENAMETOOLONG: name too long, scandir '../data/callback => {
                AND HERE MY CODE FOLLOWS

So far what i understood is that the file path string is too long ? How can we workaround an error like this if we are limited to that certain path... ?

1 Answers1

3

It looks like user is a function for some reason (depends on where it comes from / where you initialize it) and what you see in the error message ../data/callback => { ... is the stringified version of that function.

I would double check that user is really just a string identifier for the user. Based on your first example, shouldn't you use user.hash?

Samuel Bolduc
  • 18,163
  • 7
  • 34
  • 55
  • Based on your comment i double checked where the function is called and since the user is a string result from a query i tracked it in the other file and yes, the error was the user variable in that file when the callback was called was overriding the user string and this user in the code above is not the string. Thanks for pointing it out – Kristijan Stefanoski Jun 04 '19 at 13:36