
Where do my Twitter friends live?
Small World downloads everyone you follow on Twitter/X and displays them in a searchable, filterable list and interactive map β all running as a single serverless app on Val Town.
π Live demo
The app has three parts:
A lightweight wrapper around the TwitterAPI.io API that handles:
- Fetching all accounts a user follows, with automatic pagination
- Rate-limit retry logic (backs off on 429 responses)
- Memory-efficient streaming via async generators
A script you run to populate your database. It:
- Calls the Twitter API to fetch every account you follow
- Upserts each user into a
friendsSQLite table with profile info (name, handle, location, bio, avatar, follower count, etc.) - Handles batching for efficient database writes
An HTTP endpoint that serves a full-featured HTML interface with:
- List view β cards showing each friend's avatar, name, handle, location, and bio, sorted by follower count
- Map view β an interactive Leaflet map with clustered markers using a built-in geocoding dictionary (200+ cities, states, and countries)
- Search β filter by name, handle, location, or bio
- Region filters β quick-filter pills for SF Bay Area, NYC, London, Seattle, Austin, LA, Boston, and more
- Stats β total friends tracked and how many have location data
- A Val Town account
- A TwitterAPI.io API key
-
Fork this val β Click "Fork" on the val page to get your own copy
-
Set your API key β Add an environment variable called
twitterapi_keywith your TwitterAPI.io key (Val Settings β Environment Variables) -
Create the database table β Run this SQL in your val's SQLite console or via a script:
CREATE TABLE IF NOT EXISTS friends ( id TEXT PRIMARY KEY, user_name TEXT NOT NULL, name TEXT NOT NULL, location TEXT, description TEXT, url TEXT, profile_picture TEXT, cover_picture TEXT, is_blue_verified INTEGER DEFAULT 0, verified_type TEXT, followers_count INTEGER DEFAULT 0, following_count INTEGER DEFAULT 0, statuses_count INTEGER DEFAULT 0, favourites_count INTEGER DEFAULT 0, media_count INTEGER DEFAULT 0, created_at TEXT, is_automated INTEGER DEFAULT 0, downloaded_at TEXT NOT NULL DEFAULT (datetime('now')) ); -
Update the username β In
download-friends.ts, changeUSERNAMEto your Twitter handle. Inmain.ts, update the title/heading to your own name. -
Download your friends β Run
download-friends.tsas a script. This will take a few minutes depending on how many people you follow (the API has rate limits of ~1 request per 5 seconds). -
Visit your app β Open the HTTP endpoint URL for
main.tsto see your friends list and map!
- Add more locations to the
GEO_DICTgeocoding dictionary inmain.tsfor better map coverage - Add region filters for cities where you have lots of friends
- Schedule refresh β convert
download-friends.tsto an interval val to auto-refresh weekly - Use a geocoding API instead of the built-in dictionary for more accurate location mapping
- Runtime: Val Town (Deno-based serverless TypeScript)
- Database: Val Town SQLite (per-project)
- Twitter Data: TwitterAPI.io
- Map: Leaflet + Leaflet.markercluster
- Map Tiles: CARTO (light basemap)