profile
viewpoint

Ask questionsTypeError: csv(...).fromStream is not a function

For the below code,

var csvfile = "../voter/test.csv";
var fs = require("fs");
var csv = require("fast-csv");
var stream = fs.createReadStream(csvfile);

var csvStream = csv()
  .fromStream(stream, { headers: true })
  .on("data", function(data) {
    console.log(data);
  })
  .on("end", function() {
    console.log(" End of file import");
  });

stream.pipe(csvStream); 

I am getting the following error,

.fromStream(stream, { headers: true })
   ^

TypeError: csv(...).fromStream is not a function
    at Object.<anonymous> (/***/test.js:26:4)
    at Module._compile (module.js:653:30)
    at Object.Module._extensions..js (module.js:664:10)
    at Module.load (module.js:566:32)
    at tryModuleLoad (module.js:506:12)
    at Function.Module._load (module.js:498:3)
    at Function.Module.runMain (module.js:694:10)
    at startup (bootstrap_node.js:204:16)
    at bootstrap_node.js:625:3

I crossed check the library files, the function is present. Anything I have missed out?

Node version : v8.12.0

C2FO/fast-csv

Answer questions doug-martin

This is because you're calling csv().fromStream instead of csv.fromStream. Try removing the parens.

useful!

Related questions

No questions were found.
source:https://uonfu.com/
answerer
Doug Martin doug-martin C2FO Fort Collins, CO Enjoys solving hard problems and learning new languages. Actively developing with Scala, Node and Golang. Husband to a great wife and VP of Engineering at C2FO.
Github User Rank List