4

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.)

1
  • 1
    That documentation is for an older version than you have installed: "Important: this documentation covers the current version (0.2.x)" You can find updated examples in the project's README. Commented May 27, 2014 at 20:50

1 Answer 1

11

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you. I will check out the GitHub page. I was studying docs at adaltas.com, as in the URL link in my question, which must be out of date.
@Aaron Dufour is correct. They just changed the API last week, but not the docs yet. There are also a few bugs in the 0.4 API, so I would suggest using the old version for a while.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.