
Security News
The Changelog Podcast: Practical Steps to Stay Safe on npm
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.
election-tonight-client
Advanced tools

Client for the ElectionTonight API, an API for retrieving U.S. election results and exit polls conducted by Edison Research.
š API docs
āļø GitHub Repo
npm install election-tonight-client
Initialise the client.
import { ElectionTonightClient } from 'election-tonight-client';
// ElectionTonight API key
const API_KEY = 'SECRET';
// ElectionTonight event ID
const EVENT_ID = '20221108';
const client = new ElectionTonightClient(API_KEY, EVENT_ID);
Connect to your PostgreSQL database, using Postgres.js.
const databaseUrl = 'postgresql://localhost:5432/yourdb';
client.connect(databaseUrl);
Setup the event with all its metadata.
await client.setupEvent();
Get all election data in a "sweep" ...
await client.getCountyVotes();
await client.getCalls();
await client.getEditorialTurnout();
await client.getTotalExpectedVote();
await client.getMessages();
... or get just the latest in a "stream."
let updatedEntities = await client.getStreamedCountyVotes();
// Now, do something with the updated entites -- states,
// offices, etc. -- returned from the stream.
for (const updatedEntity of updatedEntites.updated) {
console.log(`New votes for state: ${updatedEntity.state}`);
}
updatedEntities = await client.getStreamedCalls();
updatedEntities = await client.getStreamedEditorialTurnout();
updatedEntities = await client.getStreamedTotalExpectedVote();
updatedEntities = await client.getStreamedMessages();
Filter requests to only get the county vote data you want.
client.filter({
states: ['TX', 'KS', 'MO'],
summary: true,
});
await client.getCountyVotes();
After you've gotten election data from the API, use Drizzle queries to retrieve records from your database.
const states = await client.db.query.state.findMany();
Close the PostgreSQL connection when you're done.
await client.disconnect();
Read more in the client's API docs.
Current coverage of ElectionTonight API endpoints. All others are planned by 2024.
| endpoint | |
|---|---|
| ā | event list |
| ā | absentee-method |
| ā | county-by-elect |
| ā | county-by-state |
| ā | delegate-district |
| ā | delegate-district-type |
| ā | election |
| ā | election/race |
| ā | party-by-office |
| ā | party-lookup |
| ā | past-county-data |
| ā | xtab-setup |
| endpoint | |
|---|---|
| ā | county-vote |
| ā | delegate-allocation |
| ā | delegate-vote |
| ā | editorial-turnout |
| ā | electoral-vote |
| ā | est |
| ā | msg |
| ā | national-delegate-summary |
| ā | total-expected-vote |
| ā | xtab |
Export a DATABASE_URL environment variable or use the built-in ephemeral PostgreSQL testcontainer.
If using testcontainers, you must have a Docker client installed, e.g., Docker Desktop.
npm run test
Run specific tests by passing a substring or regular expression to the --grep filter:
npm run test -- --grep 'your-substring'
See coverage report.
FAQs

The npm package election-tonight-client receives a total of 2 weekly downloads. As such, election-tonight-client popularity was classified as not popular.
We found that election-tonight-client demonstrated a not healthy version release cadence and project activity because the last version was released a year ago.Ā It has 0 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.

Security News
Ruby's creator Matz assumes control of RubyGems and Bundler repositories while former maintainers agree to step back and transfer all rights to end the dispute.