Val Town is a social website for writing and deploying TypeScript functions. Each function gets its own URL, runs in the cloud, and can be forked by anyone. Think GitHub Gists meets serverless — with a free API.
What Makes Val Town Special?
- Instant deploy — write a function, get a URL
- Free tier — generous limits for personal use
- Social coding — fork and remix anyone's vals
- Built-in storage — SQLite, blob storage, email
- Cron support — schedule functions to run periodically
The Hidden API: Instant Serverless Functions
// HTTP endpoint — instantly deployed
export default async function(req: Request): Promise<Response> {
const { searchParams } = new URL(req.url);
const city = searchParams.get('city') || 'London';
const weather = await fetch(
`https://wttr.in/${city}?format=j1`
).then(r => r.json());
return Response.json({
city,
temp: weather.current_condition[0].temp_C,
description: weather.current_condition[0].weatherDesc[0].value
});
}
// URL: https://username-weatherapi.web.val.run?city=Tokyo
SQLite API — Built-in Database
import { sqlite } from 'https://esm.town/v/std/sqlite';
// Create table
await sqlite.execute(`
CREATE TABLE IF NOT EXISTS pageviews (
id INTEGER PRIMARY KEY AUTOINCREMENT,
path TEXT NOT NULL,
timestamp DATETIME DEFAULT CURRENT_TIMESTAMP,
user_agent TEXT
)
`);
// Insert and query
export default async function(req: Request) {
const path = new URL(req.url).pathname;
await sqlite.execute('INSERT INTO pageviews (path, user_agent) VALUES (?, ?)',
[path, req.headers.get('user-agent')]);
const stats = await sqlite.execute(
'SELECT path, COUNT(*) as views FROM pageviews GROUP BY path ORDER BY views DESC LIMIT 10'
);
return Response.json(stats.rows);
}
Email API
import { email } from 'https://esm.town/v/std/email';
// Send email (to yourself on free tier)
export default async function() {
await email({
subject: 'Daily Report',
html: '<h1>Stats for today</h1><p>Views: 1,234</p>'
});
}
Cron API
// Runs every hour automatically
export default async function() {
const price = await fetch('https://api.coinbase.com/v2/prices/BTC-USD/spot')
.then(r => r.json());
await sqlite.execute(
'INSERT INTO btc_prices (price, timestamp) VALUES (?, datetime())',
[price.data.amount]
);
}
// Set schedule in Val Town UI: "0 * * * *"
Quick Start
Just go to val.town, write a function, and click Run. That's it.
Why Developers Love Val Town
A developer shared: "I needed a webhook endpoint for a Stripe integration. Instead of spinning up a server, deploying to AWS, and managing infrastructure — I wrote 20 lines on Val Town and had a live URL in 30 seconds."
Need quick serverless functions? Email spinov001@gmail.com or check my automation tools.
Where do you host small functions? Val Town vs Cloudflare Workers vs Deno Deploy?
Top comments (0)