Write to a CSV in Node.js

前端 未结 6 1137
伪装坚强ぢ
伪装坚强ぢ 2020-12-09 14:47

I am struggling to find a way to write data to a CSV in Node.js.

There are several CSV plugins available however they only \'write\' to stdout.

6条回答
  •  遥遥无期
    2020-12-09 15:06

    For those who prefer fast-scv:

    const { writeToPath } = require('@fast-csv/format');
    
    const path = `${__dirname}/people.csv`;
    const data = [{name: 'Stevie', id: 10}, {name: 'Ray', id: 20}];
    const options = { headers: true, quoteColumns: true };
    
    writeToPath(path, data, options)
            .on('error', err => console.error(err))
            .on('finish', () => console.log('Done writing.'));
    

提交回复
热议问题