0

I am fairly new to JavaScript, I am writing a machine learning code in which i have to include the data-set, I need the code to read all the text files stored in a directory but i am just not able to do it.

I tried to use some other modules but nothing exactly mentioned on how to get all the text files at once, they all tell how to include a single text file, the code given below is what i tried but it gives me a error "require not defined"

<script type="text/javascript">
   var fs = require('fs')
   const file = fs.readdirsync('C:\Users\akash\Desktop\New folder\ham\ham')
   console.log(file)
</script>
Chris
  • 6,272
  • 9
  • 35
  • 57
Akash
  • 195
  • 1
  • 3
  • 14
  • 2
    You've tagged this [tag:node.js] but have included an HTML ` – Quentin Sep 07 '18 at 15:17
  • And you need to escape the \ in your path to \\ when you do. – Alex K. Sep 07 '18 at 15:17
  • 1
    I would recommend you to first read what node.js is. According to the code you posted, it apparently means you don't know **where** a node script is running, hence the best place to start is the official node.js documentation. Other than that, using `fs` is likely the correct approach (you technically are close to the real solution, just think about it, but first take a look at what node is). – briosheje Sep 07 '18 at 15:18
  • Then I would suggest you to take a **deep** look at the node.js documentation: `node.js` is **not** a regular javascript environment, and does **not** run in the browser's console, that's why you're getting a `require` error. – briosheje Sep 07 '18 at 15:21
  • node.js is a regular JS environment. It is not a browser. We shouldn't think of browsers being any more "regular" then any other kind of JS environment. – Quentin Sep 07 '18 at 15:22
  • how am i supposed to use it (node.js) then, can i not run nodejs module in a .html file ?( i am really new to all this , sorry for the inconvenience ) – Akash Sep 07 '18 at 15:44

0 Answers0