Merc
Merc

Reputation: 4560

Node js - Write data to CSV File

I am trying to write incoming data to a csv file. I tried to use http://csv.adaltas.com/generate/examples/

npm install csv

But I don't get the documentation. I just want to save some data into a csv file. But even the examples are not working. E.g. the example in the link above (Using the stream API) throws the following error message:

TypeError: Cannot read property 'eql' of undefined

(First I had to change the require path, after installing the csv full package I had to require it with:

var generate = require('csv/node_modules/csv-generate');

Obviously this guy uses the same node module: https://masteringmean.com/lessons/18-Writing-to-a-CSV-file-in-Nodejs

But I can't even get his code to work. I think it was made with an older (and better documented?!) version of the csv node module.

Can anyone help me? Maybe with some code, explaining the same basic things like the one seen in the link of masteringmean.com but for the newest version?

Thanks for any hints.

Cheers

Upvotes: 2

Views: 1861

Answers (2)

emran
emran

Reputation: 922

better yet, just remove these lines:

output.should.eql('OMH,ONKCHhJmjadoA\nD,GeACHiN');

and/or

data.should.eql([ [ 'OMH', 'ONKCHhJmjadoA' ],[ 'D', 'GeACHiN' ] ]);

you really don't want the overhead of a library you're not using.

Upvotes: 0

Alexandr Lazarev
Alexandr Lazarev

Reputation: 12862

should.eql() statement that triggers the error is an assertion made with Should. You have install it at first:

npm install should --save

And require it:

var should = require('should');

The error should disappear.

Upvotes: 1

Related Questions