1

I try this const csvFile = require("pathtocsv.csv")

But it give me an error:

 pathtocsv.csv:18
return,100,physical,null,0,selected-pokemon,normal
      ^

SyntaxError: Unexpected token ,
    at new Script (vm.js:79:7)
    at createScript (vm.js:251:10)
    at Object.runInThisContext (vm.js:303:10)
    at Module._compile (internal/modules/cjs/loader.js:657:28)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:22:18)

I try to do some console.log to check where the error start, and it started on the beginning with the require.

I try to modify my csv I replace coma with semi-column but nothing happen the error is not the same but it's exactly the same type of error but on another line:

brick-break;100;physical;75;0;selected-pokemon;fighting ^^^^^

bosskay972
  • 890
  • 1
  • 6
  • 27
  • 3
    you can't require a csv. you have to read it https://stackoverflow.com/questions/23080413/library-recommendations-nodejs-reading-csv-file – arpitansu Jun 25 '19 at 09:03
  • oh woow... So it's more interesting to use text file instead of csv, it's simplier, isn't it ? – bosskay972 Jun 25 '19 at 09:06
  • 1
    based on your usage and requirements you can choose to do any format – arpitansu Jun 25 '19 at 09:07
  • 1
    if you want to read in any non-js file you can use `fs.readFileSync`. You can use like `const fs = require("fs"); const fileContent = fs.readFileSync("./pathtocsv.csv");` That will give you an arrayBuffer. Depending on the content you might be able to just call `String(file)` or you may need to do something else (if it isn't just text or if it has some encoding). – Goblinlord Jun 25 '19 at 09:20
  • That's EXACTLY what I want ! – bosskay972 Jun 25 '19 at 09:30

0 Answers0