Blog Posted November 8, 2012

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:

1
npm install civic-info

3. Require and instantiate civic-info with your Google API key:

1
var civicInfo = require("civic-info")({apiKey: "YOUR KEY"});

Alteratively, you can set a GOOGLE_API_KEY environment variable and instantiate like so:

1
var civicInfo = require("civic-info")();

Examples

Get election info and election IDs:

1
2
3
civicInfo.elections(function(data) {
  console.log(data);
});

Resulting response:

1
2
3
4
5
6
7
8
9
{
  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:

1
2
3
civicInfo.voterInfo({electionID: '4000', address: '1500 Market Street, Philadelphia, PA'}, function(data) {
  console.log(data);
});