2

I´m using fast-csv to export some data from a DB to a CSV file.

When I use the code from the example in the docs :

        var csvStream = csv.createWriteStream({headers:true}),
        writableStream = fs.createWriteStream('./csv/list.csv');

        writableStream.on('finish', function(){
            console.log('DONE!');
        });

        csvStream.pipe(writableStream);
        csvStream.write(
            [
                {
                    a: "a1",
                    b: "b1",
                    c: "c1"
                }
            ]
        );
        csvStream.end();

        res.send('export done!')    

my csv file have one entry [object Object]

1 Answer 1

2

It looks like csvStream.write() will only accept object arguments:

csvStream.write({
  a: "a1",
  b: "b1",
  c: "c1"
});

If you want to write arrays, you should use csv.write() or csv.writeToStream() (documented here, search for "Writing data" as I can't link to it directly).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.