1

I'm trying to access the directory listing of files from the http-server webserver listing configured on the localhost:4040.

I have uploaded files using the http-server to mimic a file server for testing. When I use fs to access the files in the folder with the full URL (e.g. http://localhost:4040/folder1/), I get the following error:-

Error: ENOENT: no such file or directory, scandir 'http://localhost:4040/folder1/'

The directory listing is accessible if I browse the same URL through the web browser.

fs
.readdirSync(imagePath)
.forEach((filename, index) => {
   console.log(filename
   files.push({path: imagePath, fileName: filename, fullFileName: imagePath + '/' + filename})
          });
3
  • Does File System even work like that? I'd throw an error too, if it was purposed for your directory and not a URL but I could be wrong. Commented Dec 18, 2021 at 13:16
  • You should fetch the data. Commented Dec 18, 2021 at 13:19
  • The web path is used to make client -> server request. Your server code should be using file path not web path Commented Dec 18, 2021 at 13:28

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.