JavaScript SDK
The Val Town TypeScript SDK lets you interact with our REST API from the comfort of a typed client that works well with editor autocomplete.
The Val Town SDK runs in:
- Val Town
- Node.js 18 LTS+
- Deno v1.28.0+
- Bun 1.0+
- Cloudflare Workers
- Vercel Edge Runtime
Getting started in Val Town
The quickest way to get started with the SDK is to use it in Val Town, for example by forking this val.
Authentication is set by the VAL_TOWN_API_KEY
environment
variable, which is automatically set within Val Town. You can control the
API scopes of that key in your val’s settings page.
Getting started in Node.js
Here is how to get started with the SDK, with Node.js, writing ESM. You should have Node.js already installed, version 18 or newer. There are many ways to set up JavaScript and TypeScript projects, and it’s likely that you already have a project you intend to integrate against, so we don’t document every approach.
Create a file named index.mjs
. Note that it needs to end
with .mjs
, not .js
, because this file is using ESM import
syntax. Alternatively, you can add "type": "module"
to your package.json file.
Finally, the API expects to be authenticated with an API token, so create an API token on Val Town, and set it in your terminal environment:
Now you should be able to run index.mjs
and get your profile
information: