Val Town Code SearchReturn to Val Town

API Access

You can access search results via JSON API by adding format=json to your query:

https://codesearch.val.run/...?q=function&page=1&format=json

For typeahead suggestions, use the /typeahead endpoint:

https://codesearch.val.run/typeahead?q=function

Returns an array of strings in format "username" or "username/projectName"

Found 30401 results for "function"(2155ms)

Upgrade to Deno728 words

https://docs.val.town/upgrading/upgrade-to-deno/
removed” Contact us if you need this functionality. Promises are not recursively resolved between functions. Section titled “Promises are not recursively resolved between functions” In the prior runtime, all values

Sections

User-defined functions can be synchronous 🥳

User-defined functions can be synchronous 🥳 Section titled “User-defined functions can be synchronous 🥳” In the old runtime, you would need to await the call to any @user.function. That is

setTimeout has been removed

setTimeout has been removed. Section titled “setTimeout has been removed” Contact us if you need this functionality.

Promises are not recursively resolved between functions

recursively resolved between functions. Section titled “Promises are not recursively resolved between functions” In the prior runtime, all values were recursively awaited. This means that if you returned an array

Cron evaluations has 0 arguments where it used to have 1

purple). This does not affect that fact that crons pass the Interval object to the function that has been scheduled, which allows you to get the lastRunAt value of the

Express to HTTP migration341 words

https://docs.val.town/troubleshooting/express-to-http-migration/
for the express versus HTTP types: // Express handler. export function handler(req, res) { res.send("Hello world"); } // HTTP handler. export function handler(req) { return new Response("Hello world"); } The

Sections

Parameters

for the express versus HTTP types: // Express handler. export function handler(req, res) { res.send("Hello world"); } // HTTP handler. export function handler(req) { return new Response("Hello world"); }

The response object

other details by chaining functions off of the response object, with the HTTP type, these are options you set for the Response object. // Express handler. export function handler(req, res)

The request object

string parameters, will require different code: // Express handler. export function handler(req, res) { res.send(req.query.name); } // HTTP handler. export function handler(req) { return new Response(new URL(req.url).searchParams.get("name")); }

Exports121 words

https://docs.val.town/troubleshooting/exports/
the function to run when that val is triggered. If your val has multiple exports, then we require one of them to the default export, which will be the function

Sections

Exports

the function to run when that val is triggered. If your val has multiple exports, then we require one of them to the default export, which will be the function

Save HTML form data386 words

https://docs.val.town/guides/save-html-form-data/
web browser, the server (your val function) gets sent a GET request. You can check the HTTP method using req.method and change how your val function responds. See Web forms

Sections

Create an HTTP trigger

Create an HTTP trigger. Section titled “Create an HTTP trigger” Write a val function that accepts a Request and returns a Response.

Host your form on Val Town

web browser, the server (your val function) gets sent a GET request. You can check the HTTP method using req.method and change how your val function responds. See Web forms

Your first scheduled cron603 words

https://docs.val.town/quickstarts/first-cron/
The default code will look like this: weatherNotifier.ts export default async function (interval: Interval) { // your code… } This function will be run on a schedule. By default, this

Sections

Step 2: Set up a Cron Trigger

The default code will look like this: weatherNotifier.ts export default async function (interval: Interval) { // your code… } This function will be run on a schedule. By default, this

Step 3: Get the weather

Step 3Run in Val Town ↗ import { getWeather } from "https://esm.town/v/stevekrouse/getWeather"; export default async function (interval: Interval) { let weather = await getWeather("Brooklyn, NY"); console.log(weather.current_condition[0].FeelsLikeF); } Replace Brooklyn, NY

Step 4: Send yourself an email

import { email } from "https://esm.town/v/std/email"; import { getWeather } from "https://esm.town/v/stevekrouse/getWeather"; export default async function (interval: Interval) { let weather = await getWeather("Brooklyn, NY"); let feelsLike = weather.current_condition[0].FeelsLikeF; let

Next steps

updates to Discord. weather_forecast_in_the_morning - weather forecast on Telegram. weatherBot - OpenAI Weather Bot via function calling. aqi - email alerts when AQI is unhealthy near you. …add yours here!

Early Return478 words

https://docs.val.town/vals/http/early-return/
set up a queue” In your early-returning HTTP file: early-returning.tsRun in Val Town ↗ async function handle(request: Request) { // Send off the relevant data a queue HTTP file. //

Sections

How to set up a queue

a queue” In your early-returning HTTP file: early-returning.tsRun in Val Town ↗ async function handle(request: Request) { // Send off the relevant data a queue HTTP file. // This `fetch`

Promises should otherwise be awaited

- besides this narrow use-case, errors that occur in promises won’t be properly handled and functions may run out-of-order. For example, if you use fetch to request some resource, but

Proxied fetch210 words

https://docs.val.town/std/fetch/
contains an alternative version, std/fetch, that wraps the JavaScript Fetch API to provide additional functionality. The fetch function from std/fetch reroutes requests using a proxy vendor so that requests obtain

Sections

Proxied fetch

contains an alternative version, std/fetch, that wraps the JavaScript Fetch API to provide additional functionality. The fetch function from std/fetch reroutes requests using a proxy vendor so that requests obtain

CORS387 words

https://docs.val.town/troubleshooting/cors/
Configuration. Section titled “Example: Custom CORS Configuration” Custom CorsRun in Val Town ↗ export async function myEndpoint() { return new Response("Hello", { headers: { "Access-Control-Allow-Origin": "https://specific-domain.com", "Access-Control-Allow-Methods": "GET,POST", }, });

Sections

Example: Custom CORS Configuration

Example: Custom CORS Configuration. Section titled “Example: Custom CORS Configuration” Custom CorsRun in Val Town ↗ export async function myEndpoint() { return new Response("Hello", { headers: { "Access-Control-Allow-Origin": "https://specific-domain.com", "Access-Control-Allow-Methods":

Example: Handling Preflight Requests

Example: Handling Preflight Requests. Section titled “Example: Handling Preflight Requests” For complete control over CORS behavior, you can handle OPTIONS requests explicitly: Handle Preflight Request export async function myEndpoint(req) {

Removing CORS Headers

we won’t add any custom CORS headers to your request. Remove CORS Headers export async function myEndpoint() { return new Response("Hello", { headers: { "Access-Control-Allow-Origin": "", // The minimum possible

Migrating Deprecated HTTP Vals557 words

https://docs.val.town/troubleshooting/migrating-deprecated-http-vals/
return a different random number on each request: const randomValue = Math.random(); export default async function (req: Request): Promise<Response> { return Response.json({ randomValue }); } Run in Val Town. Terminal

Sections

Accidentally re-using values.

return a different random number on each request: const randomValue = Math.random(); export default async function (req: Request): Promise<Response> { return Response.json({ randomValue }); } Run in Val Town. Terminal

Intentionally caching values for performance!

data fetching. const expensiveData = await fetchLargeDataset(); const cache = new Map(); export default async function (req: Request): Promise<Response> { const url = new URL(req.url); const key = url.searchParams.get("key"); if

Migration Checklist

be safely cached. Move variables that need to be unique per request inside the handler function. Consider opportunities to improve performance by intentionally caching expensive computations or initializations. Test your

Cron268 words

https://docs.val.town/vals/cron/
morning. Crons can be configured with cron syntax, or simple intervals like “once an hour” Functions can run up to once every 15 minutes, or once a minute, with the

Sections

Cron

morning. Crons can be configured with cron syntax, or simple intervals like “once an hour” Functions can run up to once every 15 minutes, or once a minute, with the

Type Signature

anything as a result. The return value is ignored. ExampleRun in Val Town ↗ export function cronValHandler(interval: Interval) { console.log("Cron val ran!"); } The Interval type has the following shape:

ReceiveSMSReceiveSMS.ts1 match

@Dentalabcs•Updated 39 mins ago
1export default async function ReceiveSMS(req: Request): Promise<Response> {
2 try {
3 // Parse the form data from Twilio

huyhieu.cursorrules12 matches

@lanly•Updated 1 hour ago
4
5- Ask clarifying questions when requirements are ambiguous
6- Provide complete, functional solutions rather than skeleton implementations
7- Test your logic against edge cases before presenting the final solution
8- Ensure all code follows Val Town's specific platform requirements
17- **Never bake in secrets into the code** - always use environment variables
18- Include comments explaining complex logic (avoid commenting obvious operations)
19- Follow modern ES6+ conventions and functional programming practices if possible
20
21## Types of triggers
28
29```ts
30export default async function (req: Request) {
31 return new Response("Hello World");
32}
42
43```ts
44export default async function () {
45 // Scheduled task code
46}
56
57```ts
58export default async function (email: Email) {
59 // Process email
60}
66## Val Town Standard Libraries
67
68Val Town provides several hosted services and utility functions.
69
70### Blob Storage
120```
121
122## Val Town Utility Functions
123
124Val Town provides several utility functions to help with common project tasks.
125
126### Importing Utilities
200│ ├── database/
201│ │ ├── migrations.ts # Schema definitions
202│ │ ├── queries.ts # DB query functions
203│ │ └── README.md
204│ └── routes/ # Route modules
219└── shared/
220 ├── README.md
221 └── utils.ts # Shared types and functions
222```
223
226- Hono is the recommended API framework
227- Main entry point should be `backend/index.ts`
228- **Static asset serving:** Use the utility functions to read and serve project files:
229 ```ts
230 import { readFile, serveFile } from "https://esm.town/v/std/utils@85-main/index.ts";
260- Run migrations on startup or comment out for performance
261- Change table names when modifying schemas rather than altering
262- Export clear query functions with proper TypeScript typing
263
264## Common Gotchas and Solutions
tuna

tuna9 file matches

@jxnblk•Updated 1 week ago
Simple functional CSS library for Val Town

getFileEmail4 file matches

@shouser•Updated 1 month ago
A helper function to build a file's email
lost1991
import { OpenAI } from "https://esm.town/v/std/openai"; export default async function(req: Request): Promise<Response> { if (req.method === "OPTIONS") { return new Response(null, { headers: { "Access-Control-Allow-Origin": "*",
webup
LangChain (https://langchain.com) Ambassador, KubeSphere (https://kubesphere.io) Ambassador, CNCF OpenFunction (https://openfunction.dev) TOC Member.