FeaturesTemplatesShowcaseTownie
AI
BlogDocsPricing
Log inSign up
std
stdutils
Val Town Utilities
Public
Like
3
utils
Home
Code
13
README.md
H
_tests.ts
H
example.test.ts
H
file.test.ts
file.ts
index.ts
H
parseImportMeta.test.ts
parseImportMeta.ts
H
serve-file.test.ts
serve-file.ts
H
static.test.ts
static.tsx
test.tsx
Branches
4
Pull requests
1
Remixes
7
History
Environment variables
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
/
README.md
Code
/
README.md
Search
8/7/2025
Viewing readonly version of main branch: v131
View latest version
README.md

Val Town Utilities

Tests

A comprehensive collection of utilities for building and testing applications in Val Town Projects.

  • readFile - Read files from Val Town vals
  • listFiles - List all files in a val
  • fetchTranspiledJavaScript - Fetch and transpile TypeScript/JavaScript
  • parseVal - Extract metadata from Val Town URLs
  • serveFile - Serve files with proper content types
  • getContentType - Determine MIME types for files
  • staticHTTPServer - Create a static file server
  • testServer - Create a test runner with HTML/SVG output

File Operations

File Tests

Utilities for reading and managing files in Val Town Projects.

readFile

Reads the contents of a file from the current val.

Signature:

Create val
readFile(path: string, metaImportUrl: string): Promise<string>

Example:

Create val
import { readFile } from "https://esm.town/v/std/utils/index.ts"; const content = await readFile("/README.md", import.meta.url); console.log(content);

listFiles

Lists all files in the current val with their metadata.

Signature:

Create val
listFiles(metaImportUrl: string): Promise<File[]>

Example:

Create val
import { listFiles } from "https://esm.town/v/std/utils/index.ts"; const files = await listFiles(import.meta.url); files.forEach((file) => console.log(file.path));

fetchTranspiledJavaScript

Fetches and transpiles TypeScript/JavaScript code from esm.town URLs.

Signature:

Create val
fetchTranspiledJavaScript(url: string): Promise<string>

Example:

Create val
import { fetchTranspiledJavaScript } from "https://esm.town/v/std/utils/index.ts"; const code = await fetchTranspiledJavaScript( "https://esm.town/v/std/utils@85-main/index.ts", ); console.log(code);

Notes:

  • Paths can be specified with or without leading slashes
  • TypeScript files are automatically transpiled to JavaScript

Parse Import Meta

parseVal tests

Extract metadata about the currently running Val.

parseVal

Parses Val Town metadata from an import.meta.url.

Signature:

Create val
parseVal(importMetaUrl: string): ValMetadata

Example:

Create val
import { parseVal } from "https://esm.town/v/std/utils/index.ts"; const val = parseVal(import.meta.url); console.log(val); // Output: { owner: "username", name: "valname", ... }

Prior Art:

  • @pomdtr/extractValInfo
  • @easrng/whoami

Serve File

Serve File Tests

HTTP utilities for serving val files with proper content types.

serveFile

Serves a file from the val as an HTTP Response with the correct Content-Type header.

Signature:

Create val
serveFile(path: string, metaImportUrl: string): Promise<Response>

Example:

Create val
import { serveFile } from "https://esm.town/v/std/utils/index.ts"; // In a Hono app app.get("/assets/*", async (c) => { return await serveFile(c.req.path, import.meta.url); });

getContentType

Determines the appropriate MIME type for a file based on its extension.

Signature:

Create val
getContentType(path: string): string

Example:

Create val
import { getContentType } from "https://esm.town/v/std/utils/index.ts"; console.log(getContentType("index.html")); // "text/html; charset=utf-8" console.log(getContentType("script.ts")); // "text/javascript" console.log(getContentType("data.json")); // "application/json; charset=utf-8"

Features:

  • TypeScript/TSX/JSX files are served as text/javascript
Go to top
X (Twitter)
Discord community
GitHub discussions
YouTube channel
Bluesky
Product
FeaturesPricing
Developers
DocsStatusAPI ExamplesNPM Package Examples
Explore
ShowcaseTemplatesNewest ValsTrending ValsNewsletter
Company
AboutBlogCareersBrandhi@val.town
Terms of usePrivacy policyAbuse contact
© 2025 Val Town, Inc.