Sho*_*oko 3 javascript csv node.js
我正在尝试执行一个读取CSV文件的示例脚本.我从这个页面复制了样本:
http://www.adaltas.com/projects/node-csv/
我收到此错误:
csv()
^
TypeError: object is not a function
at Object.<anonymous> (/Users/paulchernoch/Documents/Chris Leung/read-csv-test.js:8:1)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:906:3
Run Code Online (Sandbox Code Playgroud)
示例代码(修改为使用我的文件名):
var csv = require('csv');
var fs = require('fs');
csv()
.from.stream(fs.createReadStream(__dirname+'/f1dcca4e8c5f76b3.csv'))
.to.path(__dirname+'/test.txt')
.transform( function(row){
return row;
})
.on('record', function(row,index){
console.log('#'+index+' ' /* +JSON.stringify(row) */);
})
.on('end', function(count){
console.log('Number of lines: '+count);
})
.on('error', function(error){
console.log(error.message);
});
Run Code Online (Sandbox Code Playgroud)
我从命令行调用脚本,如下所示:
> node read-csv-test.js
Run Code Online (Sandbox Code Playgroud)
为了验证我是否安装了正确的CSV模块,我使用了节点包管理器:
$ npm list
/Users/paulchernoch
??? csv@0.4.0
? ??? csv-generate@0.0.4
? ??? csv-parse@0.0.3
? ??? csv-stringify@0.0.2
? ??? stream-transform@0.0.2
??? express@4.3.0
? ??? accepts@1.0.1
? ? ??? mime@1.2.11
? ? ??? negotiator@0.4.3
? ??? buffer-crc32@0.2.1
? ??? cookie@0.1.2
? ??? cookie-signature@1.0.3
? ??? debug@0.8.1
? ??? escape-html@1.0.1
? ??? fresh@0.2.2
? ??? merge-descriptors@0.0.2
? ??? methods@1.0.0
? ??? parseurl@1.0.1
? ??? path-to-regexp@0.1.2
? ??? proxy-addr@1.0.0
? ? ??? ipaddr.js@0.1.2
? ??? qs@0.6.6
? ??? range-parser@1.0.0
? ??? send@0.3.0
? ? ??? debug@0.8.0
? ? ??? mime@1.2.11
? ??? serve-static@1.1.0
? ??? type-is@1.2.0
? ? ??? mime@1.2.11
? ??? utils-merge@1.0.0
??? jade@1.3.1
? ??? character-parser@1.2.0
? ??? commander@2.1.0
? ??? constantinople@2.0.0
? ? ??? uglify-js@2.4.13
? ? ??? async@0.2.10
? ? ??? optimist@0.3.7
? ? ? ??? wordwrap@0.0.2
? ? ??? source-map@0.1.33
? ? ? ??? amdefine@0.1.0
? ? ??? uglify-to-browserify@1.0.2
? ??? mkdirp@0.3.5
? ??? monocle@1.1.51
? ? ??? readdirp@0.2.5
? ? ??? minimatch@0.3.0
? ? ??? lru-cache@2.5.0
? ? ??? sigmund@1.0.0
? ??? transformers@2.1.0
? ? ??? css@1.0.8
? ? ? ??? css-parse@1.0.4
? ? ? ??? css-stringify@1.0.5
? ? ??? promise@2.0.0
? ? ? ??? is-promise@1.0.1
? ? ??? uglify-js@2.2.5
? ? ??? optimist@0.3.7
? ? ? ??? wordwrap@0.0.2
? ? ??? source-map@0.1.33
? ? ??? amdefine@0.1.0
? ??? with@3.0.0
? ??? uglify-js@2.4.13
? ??? async@0.2.10
? ??? optimist@0.3.7
? ? ??? wordwrap@0.0.2
? ??? source-map@0.1.33
? ? ??? amdefine@0.1.0
? ??? uglify-to-browserify@1.0.2
??? mariasql@0.1.20
? ??? lru-cache@2.3.1
??? stylus@0.45.1
??? css-parse@1.7.0
??? debug@0.8.1
??? glob@3.2.11
? ??? inherits@2.0.1
? ??? minimatch@0.3.0
? ??? lru-cache@2.5.0
? ??? sigmund@1.0.0
??? mkdirp@0.3.5
??? sax@0.5.8
Run Code Online (Sandbox Code Playgroud)
我错过了什么?我正在运行MAC OS X 10.6.8.我使用Homebrew安装了节点.我在Windows上成功使用了node和javascript,但这是我第一次尝试在MAC上使用node.(最终目标是解析CSV文件并将其加载到MariaDb中.)
Aar*_*our 11
目前还不清楚你的示例代码在哪里,但它可能已经不再有效了 - 0.4最近发布了一个新版本的模块(),它有一个非常不同的API.您可以在项目的GitHub页面上查看新文档,也可以通过以下方式安装旧版本:
npm remove csv
npm install csv@0.3.7
Run Code Online (Sandbox Code Playgroud)
0.3.7 有你似乎正在反对的API,但如果有必要你当然可以走得更远.
| 归档时间: |
|
| 查看次数: |
6257 次 |
| 最近记录: |