Reputation: 43
I am trying to execute a sample script that reads a CSV file. I copied the sample from this page:
http://www.adaltas.com/projects/node-csv/
I get this error:
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
The sample code (modified to use my file names):
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);
});
I invoked the script from the command line like this:
> node read-csv-test.js
To verify whether I had the proper CSV module installed, I used the node package manager:
$ npm list
/Users/paulchernoch
├─┬ [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ └── [email protected]
├─┬ [email protected]
│ ├─┬ [email protected]
│ │ ├── [email protected]
│ │ └── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├─┬ [email protected]
│ │ └── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├─┬ [email protected]
│ │ ├── [email protected]
│ │ └── [email protected]
│ ├── [email protected]
│ ├─┬ [email protected]
│ │ └── [email protected]
│ └── [email protected]
├─┬ [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├─┬ [email protected]
│ │ └─┬ [email protected]
│ │ ├── [email protected]
│ │ ├─┬ [email protected]
│ │ │ └── [email protected]
│ │ ├─┬ [email protected]
│ │ │ └── [email protected]
│ │ └── [email protected]
│ ├── [email protected]
│ ├─┬ [email protected]
│ │ └─┬ [email protected]
│ │ └─┬ [email protected]
│ │ ├── [email protected]
│ │ └── [email protected]
│ ├─┬ [email protected]
│ │ ├─┬ [email protected]
│ │ │ ├── [email protected]
│ │ │ └── [email protected]
│ │ ├─┬ [email protected]
│ │ │ └── [email protected]
│ │ └─┬ [email protected]
│ │ ├─┬ [email protected]
│ │ │ └── [email protected]
│ │ └─┬ [email protected]
│ │ └── [email protected]
│ └─┬ [email protected]
│ └─┬ [email protected]
│ ├── [email protected]
│ ├─┬ [email protected]
│ │ └── [email protected]
│ ├─┬ [email protected]
│ │ └── [email protected]
│ └── [email protected]
├─┬ [email protected]
│ └── [email protected]
└─┬ [email protected]
├── [email protected]
├── [email protected]
├─┬ [email protected]
│ ├── [email protected]
│ └─┬ [email protected]
│ ├── [email protected]
│ └── [email protected]
├── [email protected]
└── [email protected]
What am I missing? I am running MAC OS X 10.6.8. I installed node using Homebrew. I have successfully used node and javascript on Windows, but this is my very first attempt to use node on a MAC. (The ultimate goal is to parse CSV files and load them into MariaDb.)
Upvotes: 4
Views: 10241
Reputation: 17535
Its not clear where you got your sample code, but it is probably no longer valid - a new version of the module (0.4
) was released recently with a very different API. You can either check out the new documentation at the project's GitHub page or install an older version by:
npm remove csv
npm install [email protected]
0.3.7
has the API you appear to be working against, but you can of course go farther back if necessary.
Upvotes: 11