
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
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 1 weekly downloads. As such, election-tonight-client popularity was classified as not popular.
We found that election-tonight-client demonstrated a healthy version release cadence and project activity because the last version was released less than 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
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.