Node js and data fetching
So here we are at Week2 in a little more server-side Javascript via node js.. As usual, we assume these commands are being executed on AWS on a EC2 t1.micro instance running Ubuntu 12.04.2 LTS. So what we have is to pull data from Yahoo API. Now instead of parsing complete html pages for, let's say, financial data in our case, we use a (hidden) fetch command.
In a nutshell, if I need data for some stocks(in a csv), I use -
//http://finance.yahoo.com/d/quotes.csv?s=GE+PTR+MSFT&f=snd1l1yr
(where sysmbols used in this URL means something, like d stands for Dividend/Share; s for Symbol etc). Find it here.
After this let's implement the node js script[using node modules such as restler, csv and accounting]:
# Download and make executable
wget https://spark-public.s3.amazonaws.com/startup/code/market-research.js wget https://spark-public.s3.amazonaws.com/startup/code/market-research-wrapper.js # Install npm dependencies. This will create a node_modules directory in # the current working directory. Don't cd into other directories right # now; later we'll show how to install modules globally. npm install restler csv accounting # As a script node market-research.js node market-research.js FB ORCL # As an executable chmod 777 market-research.js ./market-research.js ./market-research.js GOOG CRM # As a module, through another program invoked as a script node market-research-wrapper.js # As a module, through another program being invoked as an executable chmod 777 market-research-wrapper.js ./market-research-wrapper.js # Also as a module - but with the external code being input at the command line # via the -e flag node -e "require('./market-research.js')" node -e "var mr = require('./market-research.js'); mr.marketResearch();" node -e "var mr = require('./market-research.js'); mr.marketResearch([\"FB\",\"ORCL\"]);"












