Using the civic-info Node.js Module to Get Voter and Election Info
Inspired by election apps like vote, I wrote civic-info.js, a simple Node.js module to interface with Google’s Civic Info API.
## Getting Started
1. Secure a Google API key. 2. Install civic-info:
npm install civic-info
3. Require and instantiate civic-info with your Google API key:
var civicInfo = require("civic-info")({apiKey: "YOUR KEY"});
Alteratively, you can set a GOOGLE_API_KEY
environment variable and instantiate like so:
var civicInfo = require("civic-info")();
Examples
Get election info and election IDs:
civicInfo.elections(function(data) {
console.log(data);
});
Resulting response:
{
kind: 'civicinfo#electionsQueryResponse',
elections:
[ {
id: '2000',
name: 'VIP Test Election',
electionDay: '2013-06-06'
} ]
}
Get voter information such as polling places, contests, candidates, etc. surrounding an election whose electionID is ’4000′ for a voter who lives at 1500 Market Street in Philadelphia:
civicInfo.voterInfo({electionID: '4000', address: '1500 Market Street, Philadelphia, PA'}, function(data) {
console.log(data);
});