• Blog
  • Docs
  • Pricing
  • We’re hiring!
Log inSign up
stevekrouse

stevekrouse

smallworld

Where do my twitter friends live?
Public
Like
1
smallworld
Home
Code
4
README.md
download-friends.ts
H
main.ts
twitterapi-sdk.ts
Connections
Environment variables
1
Branches
1
Pull requests
Remixes
History
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
Sign up now
Code
/
Code
/
Search
main.ts
https://stevekrouse--0fbe7af0084911f1927342dde27851f2.web.val.run
README.md

🌍 Small World

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

How It Works

The app has three parts:

1. Twitter API SDK (twitterapi-sdk.ts)

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

2. Data Downloader (download-friends.ts)

A script you run to populate your database. It:

  • Calls the Twitter API to fetch every account you follow
  • Upserts each user into a friends SQLite table with profile info (name, handle, location, bio, avatar, follower count, etc.)
  • Handles batching for efficient database writes

3. Web App (main.ts)

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

Setup Your Own

Prerequisites

  • A Val Town account
  • A TwitterAPI.io API key

Steps

  1. Fork this val β€” Click "Fork" on the val page to get your own copy

  2. Set your API key β€” Add an environment variable called twitterapi_key with your TwitterAPI.io key (Val Settings β†’ Environment Variables)

  3. 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')) );
  4. Update the username β€” In download-friends.ts, change USERNAME to your Twitter handle. In main.ts, update the title/heading to your own name.

  5. Download your friends β€” Run download-friends.ts as 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).

  6. Visit your app β€” Open the HTTP endpoint URL for main.ts to see your friends list and map!

Customization Ideas

  • Add more locations to the GEO_DICT geocoding dictionary in main.ts for better map coverage
  • Add region filters for cities where you have lots of friends
  • Schedule refresh β€” convert download-friends.ts to an interval val to auto-refresh weekly
  • Use a geocoding API instead of the built-in dictionary for more accurate location mapping

Tech Stack

  • 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)
Code
README.mddownload-friends.ts
H
main.ts
twitterapi-sdk.ts
FeaturesVersion controlCode intelligenceCLIMCP
Use cases
TeamsAI agentsSlackGTM
DocsShowcaseTemplatesNewestTrendingAPI examplesNPM packages
AboutAlternativesPricingBlogNewsletterCareers
We’re hiring!
Brandhi@val.townStatus
X (Twitter)
Discord community
GitHub discussions
YouTube channel
Bluesky
Open Source Pledge
Terms of usePrivacy policyAbuse contact
Β© 2026 Val Town, Inc.