Why does an error occur when running the code shown below? (It was used in one of the homework in the Stanford Startup course on Coursera: https://class.coursera.org/startup-001/quiz/attempt?quiz_id=149 )
The course took place in June-September 2013, so there may have been node or csv updates that broke the script, maybe? The homework is not related to fixing the script, so this question is not a cheat, and the course is not currently running.
So, Wednesday: Ubuntu 14.04 (kernel 3-13-0-29-shared), node v0.11.13, npm v1.4.9
And I have npm install 'd csv, account and restler in the home directory, as well as a script.
It completely surpassed me ....: - (
error message:
[ ubuntu@ip-xxx-xxx -xxx-xxx:~]$node market-research.js Invoked at command line. Wrote market-research.csv Symbol Name Market Cap Previous Close Price P/E Ratio Shares EPS Earnings /home/ubuntu/market-research.js:47 csv() ^ TypeError: object is not a function at csv2console (/home/ubuntu/market-research.js:47:5) at Request.response2console (/home/ubuntu/market-research.js:65:13) at Request.EventEmitter.emit (events.js:110:17) at Request.mixin._fireSuccess (/home/ubuntu/node_modules/restler/lib/restler.js:226:10) at /home/ubuntu/node_modules/restler/lib/restler.js:158:20 at IncomingMessage.parsers.auto (/home/ubuntu/node_modules/restler/lib/restler.js:394:7) at Request.mixin._encode (/home/ubuntu/node_modules/restler/lib/restler.js:195:29) at /home/ubuntu/node_modules/restler/lib/restler.js:154:16 at Request.mixin._decode (/home/ubuntu/node_modules/restler/lib/restler.js:170:7) at IncomingMessage.<anonymous> (/home/ubuntu/node_modules/restler/lib/restler.js:147:14) [ ubuntu@ip-xxx-xxx-xxx-xxx :~]$
the code:
#!/usr/bin/env node var util = require('util'); var fs = require('fs'); var rest = require('restler'); var csv = require('csv'); var accounting = require('accounting'); var CSVFILE_DEFAULT = "market-research.csv"; var SYMBOLS_DEFAULT = ["GOOG", "FB", "AAPL", "YHOO", "MSFT", "LNKD", "CRM"]; var COLUMNS_DEFAULT = 'snj1pr';
contents of market-research.csv generated by the script:
"GOOG","Google Inc.",386.6B,569.20,29.49 "FB","Facebook, Inc.",194.5B,73.855,78.49 "AAPL","Apple Inc.",613.8B,102.25,16.49 "YHOO","Yahoo! Inc.",38.302B,38.31,33.11 "MSFT","Microsoft Corpora",374.3B,44.88,17.06 "LNKD","LinkedIn Corporat",27.747B,223.26,N/A "CRM","Salesforce.com In",36.577B,58.29,N/A