Skip to content

Instantly share code, notes, and snippets.

@raviagheda
Created August 30, 2022 11:53
Show Gist options
  • Save raviagheda/5fa58cd5a55cf8e6e52dc45b2b0ea253 to your computer and use it in GitHub Desktop.
Save raviagheda/5fa58cd5a55cf8e6e52dc45b2b0ea253 to your computer and use it in GitHub Desktop.
Generate CSV from JSON Object

Install npm package objects-to-csv

import * as ObjectsToCsv from 'objects-to-csv';

const createCSV = async (data: any, name: string) => {
    const csv = new ObjectsToCsv(data);
    await csv.toDisk(path.join(__dirname, '../data/processed-csvs/' + name) );
    return csv.toString();
}

// Function Call
createCSV([{
    name: 'Ravi',
    surname: 'Agheda'
}], 'file.csv');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment