Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Write to a CSV in Node.js

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.

Ideally I want to write on a row-by-row basis using a loop.

like image 988
Phil Bottomley Avatar asked Apr 19 '12 11:04

Phil Bottomley


People also ask

How do I send a CSV file in react to node js?

Make sure your React. js server is running with npm run . Go to http://localhost:3000 and click on Import Data to open the importer modal. Upload your CSV file, match the columns and then click import.


1 Answers

You can use fs (https://nodejs.org/api/fs.html#fs_fs_writefile_file_data_options_callback):

var dataToWrite; var fs = require('fs');  fs.writeFile('form-tracking/formList.csv', dataToWrite, 'utf8', function (err) {   if (err) {     console.log('Some error occured - file either not saved or corrupted file saved.');   } else{     console.log('It\'s saved!');   } }); 
like image 156
John Vandivier Avatar answered Sep 21 '22 05:09

John Vandivier