Skip to content

how to use transform #577

@mingxin-yang

Description

@mingxin-yang

I want to modify a csv file, add a status column, and add the corresponding data, but I can't use the following code, how can I modify it? went on

let path = __dirname + '/emails/' + value.filename + '.csv';

            const fields = ['email', 'fullname', 'status'];
            const opts = { fields, transform:[function (buf, enc, next) {
              return {
                ...buf,
                  email:job1.data.email,
                  fullname:job1.data.fullname,
                  status:value.status 
              }
            }]};
            const transformOpts = {objectMode: true};
            const json2csv = new Transform(opts, transformOpts);
            const input = fs.createReadStream(path, { encoding: 'utf8' });
            const output = fs.createWriteStream(path, { encoding: 'utf8' });

            const processor = input.pipe(json2csv).pipe(output);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions