【发布时间】:2015-05-07 18:07:29
【问题描述】:
我是节点 js 的新手。
我的本地系统中有一个 csv 文件,我想使用节点 js 将其上传到本地 PostgreSQL 数据库。
我正在尝试以下代码:
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);
})
它的读取数据。 现在我想将它导入到 postgrsql 数据库中。
我在哪里可以获得教程或任何其他帮助。
【问题讨论】:
-
如果 postgres 有内置功能,为什么还需要 node?推荐人:stackoverflow.com/questions/2987433/…
-
我还必须创建一个文件对话框,不会在 postgresql 中创建
-
也许你可以在没有 csv 模块的情况下编写查询
COPY zip_codes FROM '/path/to/csv/ZIP_CODES.txt' DELIMITER ',' CSV;? -
应该是这样的http路径mycsv.com/file.csv
-
@RajatModi 如果我需要本地路径,那么我应该做些什么改变?
标签: javascript node.js nodes