0

So I'm writing a website that shows images, and I need to get all the filenames of the images.

I tried:

var fs = require("fs");
var files = fs.readdirSync("./images");

But it says 'Uncaught ReferenceError: require is not defined'

  • Does this answer your question? [How do you get a list of the names of all files present in a directory in Node.js?](https://stackoverflow.com/questions/2727167/how-do-you-get-a-list-of-the-names-of-all-files-present-in-a-directory-in-node-j) – grenzbotin Jan 28 '23 at 10:25
  • 1
    That error happens when you try running that code in a browser and not in a nodejs server. Check out this quickstart guide for node https://nodejs.org/en/docs/guides/getting-started-guide/ – MacroSacramento Jan 28 '23 at 10:25

0 Answers0