How to Use Val Town for Quick Scripts: A Fast Serverless REPL

Val Town is a cloud-based platform where you can write, run, and share small scripts (called “vals”) without managing any infrastructure. It supports JavaScript and TypeScript, offers scheduling, HTTP endpoints, and built-in secrets management. If you need to test a snippet, automate a task, or create a lightweight API in minutes, Val Town is the tool for the job.

Getting started is simple: sign up for free at val.town, then open a new val. You can write code directly in the browser editor and hit “Run” to see instant output. No terminal, no deployment pipeline. This makes it perfect for prototyping, data transformation, or integrating with third-party services.

Article illustration

1. Writing and Executing Your First Val

After logging in, click “New Val”. Choose between a Script (runs on demand or on a schedule) or a HTTP (returns a response when someone visits a URL). For a quick script, select “Script”. Type your code – even a simple console.log("Hello, Val!") – and press Cmd+Enter (or the Run button). The output appears in the console panel instantly. You can also install npm packages by importing them as usual; Val Town auto-resolves dependencies.

2. Using Secrets and Persistent State

Hardcoding API keys is unsafe. Val Town provides a secrets store. In your val, access secrets via Deno.env.get("MY_KEY") (Val Town uses Deno under the hood). Set secrets in the “Secrets” tab of your account settings. For persistent data across runs (e.g., a counter), use the built-in SQLite database – each val gets a private, in-memory SQLite instance (usable via val.db). This lets you store small amounts of data without an external service.

3. Scheduling and Sharing Vals

To run a val automatically, click the clock icon in the editor and set a cron expression (e.g., 0 8 * * * for daily at 8 AM). Your val will execute on schedule, perfect for mailers or log checks. Sharing is as easy as copying the unique val URL. You can also import others’ vals by referencing their ID (import { myval } from "https://val.town/v/username.myval") – a powerful way to compose functionality.

4. Building a Quick HTTP Endpoint

Need a tiny API? Choose “HTTP” when creating a val. Write a handler function like export default async function(req: Request) { return new Response("Hello, world!"); }. Val Town gives you a URL like https://val.town/v/username.hello. Deploy instantly – no port forwarding, no server config. Useful for webhooks, form endpoints, or mocked services during development.

Val Town turns ephemeral scripts into real, runnable services with zero DevOps. Start with small experiments, then layer in scheduling, secrets, and sharing. Within minutes, you’ll have a production‑ready snippet without leaving your browser.

sarah antaboga
Author: sarah antaboga

Leave a Reply

Your email address will not be published. Required fields are marked *