I am new to node js.
I have a csv file in my local system that I want to upload it local PostgreSQL Database using node js.
I am trying the following code:
var csv = require('csv-stream');
var request = require('request');
var fs = require('fs');
// All of these arguments are optional.
var options = {
delimiter : '\t', // default is ,
endLine : '\n', // default is \n,
// by default read the first line and use values found as columns
// columns : ['Settlement Ref No.', 'Order Type','Fulfilment Type','Seller SKU','wsn'],
escapeChar : '"', // default is an empty string
enclosedChar : '"' // default is an empty string
}
var csvStream = csv.createStream(options);
fs.createReadStream('C:\\Users\\YAM\\Documents\\fk_starchi.csv').pipe(csvStream)
.on('error',function(err){
console.error(err);
})
.on('data',function(data){
// outputs an object containing a set of key/value pair representing a line found in the csv file.
// console.log(data);
})
.on('column',function(key,value){
// outputs the column name associated with the value found
// console.log('#' + key + ' = ' + value);
console.log('# ' + value);
})
Its reading data . now i want to import it on postgrsql database.
Where can I get a tutorial or any other help to do this.