<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: bunny.net</title>
    <description>The latest articles on DEV Community by bunny.net (bunnydotnet).</description>
    <link>https://dev.to/bunnydotnet</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Forganization%2Fprofile_image%2F15819%2F7f50df6c-ae18-423b-bb54-2629a14417a4.png</url>
      <title>DEV Community: bunny.net</title>
      <link>https://dev.to/bunnydotnet</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/bunnydotnet"/>
    <language>en</language>
    <item>
      <title>Moving your vals to bunny.net</title>
      <dc:creator>Jamie Barton</dc:creator>
      <pubDate>Fri, 20 Nov 2026 14:41:14 +0000</pubDate>
      <link>https://dev.to/bunnydotnet/moving-your-vals-to-bunnynet-2ki4</link>
      <guid>https://dev.to/bunnydotnet/moving-your-vals-to-bunnynet-2ki4</guid>
      <description>&lt;p&gt;Val Town lets you write a function in the browser and get a URL back a second later. I've loved that idea since the first time I used it… small pieces of code with a database and file storage close at hand, and no server to look after.&lt;/p&gt;

&lt;p&gt;On November 10, Steve Krouse &lt;a href="https://blog.val.town/winding-down" rel="noopener noreferrer"&gt;announced that Val Town is winding down&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Bunny Database is built on libSQL too. Your vals already speak its language, so most of the move is about where the code runs and where the files live, and the database queries come along as they are.&lt;/p&gt;

&lt;p&gt;Before we begin, there are a few dates that matter:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Date&lt;/th&gt;
&lt;th&gt;What happens&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Nov 10, 2026&lt;/td&gt;
&lt;td&gt;New signups and plan upgrades closed&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Dec 10, 2026&lt;/td&gt;
&lt;td&gt;Read-only mode&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Jan 10, 2027&lt;/td&gt;
&lt;td&gt;All other services end&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Feb 1, 2027&lt;/td&gt;
&lt;td&gt;Val Town is open-sourced&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Val Town gives no later date for SQLite and blob storage, so plan to have your data copied before January 10.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where each piece goes
&lt;/h2&gt;

&lt;p&gt;A val maps onto three bunny.net products:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;the HTTP handler runs as an &lt;a href="https://bunny.net/edge-scripting/" rel="noopener noreferrer"&gt;Edge Script&lt;/a&gt;,&lt;/li&gt;
&lt;li&gt;the SQLite tables move to &lt;a href="https://bunny.net/database/" rel="noopener noreferrer"&gt;Bunny Database&lt;/a&gt;,&lt;/li&gt;
&lt;li&gt;and blobs become files in &lt;a href="https://bunny.net/storage/" rel="noopener noreferrer"&gt;Bunny Storage&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;On Val Town&lt;/th&gt;
&lt;th&gt;On bunny.net&lt;/th&gt;
&lt;th&gt;What changes in your code&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;HTTP trigger: a default export that takes a &lt;code&gt;Request&lt;/code&gt; and returns a &lt;code&gt;Response&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;A standalone Edge Script that passes a handler to &lt;code&gt;BunnySDK.net.http.serve()&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;One wrapper line&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;std/sqlite&lt;/code&gt;, an &lt;code&gt;@libsql/client&lt;/code&gt; instance&lt;/td&gt;
&lt;td&gt;Bunny Database, built on libSQL&lt;/td&gt;
&lt;td&gt;The import and the client setup&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;std/blob&lt;/code&gt;, backed by Amazon S3 (scoped) or Cloudflare R2 (global)&lt;/td&gt;
&lt;td&gt;A Bunny Storage zone through &lt;code&gt;@bunny.net/storage-sdk&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;A small helper with the same method names&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Environment variables read with &lt;code&gt;Deno.env.get()&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;Environment variables and secrets on the script, read with &lt;code&gt;process.env&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;Where you read them&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Each script gets the standard Web APIs, and code written against &lt;code&gt;Request&lt;/code&gt;, &lt;code&gt;Response&lt;/code&gt;, and &lt;code&gt;fetch&lt;/code&gt; keeps working, so most of the migration is swapping imports.&lt;/p&gt;

&lt;p&gt;The guide follows the dashboard first, since that's closest to how Val Town felt. If you'd rather stay in the terminal, the same steps are collected into one CLI run near the end, followed by a prompt you can hand to a coding agent.&lt;/p&gt;

&lt;h2&gt;
  
  
  Port your code into one file
&lt;/h2&gt;

&lt;p&gt;The goal of this step is a single &lt;code&gt;main.ts&lt;/code&gt; that you can paste into the dashboard and keep editing there, the way you did on Val Town.&lt;/p&gt;

&lt;h3&gt;
  
  
  The HTTP handler
&lt;/h3&gt;

&lt;p&gt;An HTTP val's entry file default-exports a function that takes a &lt;code&gt;Request&lt;/code&gt; and returns a &lt;code&gt;Response&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Request&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Response&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;Response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"hello, http!"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A standalone Edge Script uses the same function. Pass it to &lt;code&gt;serve()&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nc"&gt;BunnySDK&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"npm:@bunny.net/edgescript-sdk"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;handler&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Request&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Response&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;Response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"hello, http!"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;BunnySDK&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;net&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;serve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;handler&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Vals built on Hono keep their routes. Hand &lt;code&gt;app.fetch&lt;/code&gt; to &lt;code&gt;serve()&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nc"&gt;BunnySDK&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"npm:@bunny.net/edgescript-sdk"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nc"&gt;Hono&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"npm:hono"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Hono&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"/"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;ok&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nc"&gt;BunnySDK&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;net&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;serve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;npm:&lt;/code&gt; prefix lets the script load packages with no build step, so the file you paste into the code editor is the file that runs. Imports from &lt;code&gt;esm.town&lt;/code&gt; load from Val Town's servers, so swap each one for the npm or JSR package it wraps before January 10.&lt;/p&gt;

&lt;h3&gt;
  
  
  The database client
&lt;/h3&gt;

&lt;p&gt;Val Town's &lt;code&gt;sqlite&lt;/code&gt; object is an initialized &lt;code&gt;@libsql/client&lt;/code&gt; instance, and Bunny Database's TypeScript docs use the same client. Swap the import for a client under the same name at the top of your script, and your &lt;code&gt;execute()&lt;/code&gt; and &lt;code&gt;batch()&lt;/code&gt; calls keep their arguments, placeholders, and the &lt;code&gt;rows&lt;/code&gt; and &lt;code&gt;columns&lt;/code&gt; result shape:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Before&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;sqlite&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"https://esm.town/v/std/sqlite/main.ts"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// After&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;createClient&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"npm:@libsql/client/web"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nb"&gt;process&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"node:process"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;sqlite&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createClient&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;BUNNY_DATABASE_URL&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;authToken&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;BUNNY_DATABASE_AUTH_TOKEN&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The two environment variables don't exist yet. The database step adds them to your script for you.&lt;/p&gt;

&lt;p&gt;Val Town blobs are values stored under a key. Bunny Storage stores files by path in a storage zone, so each blob key becomes a file path. This helper keeps your &lt;code&gt;get&lt;/code&gt;, &lt;code&gt;set&lt;/code&gt;, &lt;code&gt;getJSON&lt;/code&gt;, &lt;code&gt;setJSON&lt;/code&gt;, and &lt;code&gt;delete&lt;/code&gt; call sites unchanged:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nc"&gt;BunnyStorageSDK&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"npm:@bunny.net/storage-sdk"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;zone&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;BunnyStorageSDK&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;zone&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;connect_with_accesskey&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="nc"&gt;BunnyStorageSDK&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;regions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;StorageRegion&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Falkenstein&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nb"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;BUNNY_STORAGE_ZONE&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nb"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;BUNNY_STORAGE_PASSWORD&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;blob&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;BodyInit&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;body&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Response&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nc"&gt;BunnyStorageSDK&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;file&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;upload&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;zone&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sb"&gt;`/${key}`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

  &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;stream&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nc"&gt;BunnyStorageSDK&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;file&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;download&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;zone&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sb"&gt;`/${key}`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Response&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;stream&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

  &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="nf"&gt;setJSON&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;unknown&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;body&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Response&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nc"&gt;BunnyStorageSDK&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;file&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;upload&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;zone&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sb"&gt;`/${key}`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="n"&gt;contentType&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"application/json"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

  &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="nf"&gt;getJSON&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="kc"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="c1"&gt;// Val Town's getJSON returns undefined for a missing key&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

  &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;delete&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nc"&gt;BunnyStorageSDK&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;file&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;remove&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;zone&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sb"&gt;`/${key}`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;list&lt;/code&gt; is left out on purpose. Val Town lists every key under a prefix, and &lt;code&gt;BunnyStorageSDK.file.list()&lt;/code&gt; returns the contents of one folder, so a val that walks its keys needs a small recursive version of its own. Change &lt;code&gt;Falkenstein&lt;/code&gt; if you create your storage zone in another region.&lt;/p&gt;

&lt;p&gt;Your &lt;code&gt;main.ts&lt;/code&gt; now has the imports, the &lt;code&gt;sqlite&lt;/code&gt; client, the &lt;code&gt;blob&lt;/code&gt; helper, and your routes, ending with the &lt;code&gt;serve()&lt;/code&gt; call.&lt;/p&gt;

&lt;h2&gt;
  
  
  Create the Edge Script
&lt;/h2&gt;

&lt;p&gt;In the bunny.net dashboard, Add a New Edge Script. Make sure to select&amp;nbsp;&lt;strong&gt;Deploy and edit on bunny.net&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fiktbq6g07xwf5os7u35g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fiktbq6g07xwf5os7u35g.png" alt=" " width="799" height="572"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then give your script a name, select standalone for its type, and create a new database:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F8rh1667e75nd0kkaer5z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F8rh1667e75nd0kkaer5z.png" alt=" " width="800" height="1367"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The dashboard creates an empty database and adds &lt;code&gt;BUNNY_DATABASE_URL&lt;/code&gt; and &lt;code&gt;BUNNY_DATABASE_AUTH_TOKEN&lt;/code&gt; to the script for you, which is what the &lt;code&gt;sqlite&lt;/code&gt; client reads. If you already have a database, you can choose to use that existing one instead.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fpwkhgtt2j90qmlfsu8tx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fpwkhgtt2j90qmlfsu8tx.png" alt=" " width="799" height="502"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The database replicates across every region, so reads stay close to wherever the script runs, and replicas are provisioned on demand.&lt;/p&gt;

&lt;p&gt;Once the script exists, paste your &lt;code&gt;main.ts&lt;/code&gt; into its code editor and save it. Hold off on publishing until your data and blobs are in place.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F9g1a09dqg241nskq337d.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F9g1a09dqg241nskq337d.png" alt=" " width="800" height="478"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Standalone scripts act as the origin for their pull zone. The CDN answers cached requests itself and calls your script on a cache miss. An API that must run on every request needs the Run script before cache option, which sits in the script settings.&lt;/p&gt;

&lt;h2&gt;
  
  
  Move the database
&lt;/h2&gt;

&lt;p&gt;The database you created with the script starts empty, and that matters here. Val Town's dump uses &lt;code&gt;CREATE TABLE IF NOT EXISTS&lt;/code&gt;, so a table that already exists with the same name keeps its old structure and the inserts land on top of it. If you chose Use existing, check it holds none of your val's tables yet.&lt;/p&gt;

&lt;h3&gt;
  
  
  Copy your data
&lt;/h3&gt;

&lt;p&gt;Open the val in Val Town and choose Dump as SQL. The dump carries your tables, rows, indexes, triggers, and autoincrement counters.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fhyjzg3kunv3k1cksb3lg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fhyjzg3kunv3k1cksb3lg.png" alt=" " width="800" height="368"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Copy the dump into the database's Database editor and delete the &lt;code&gt;BEGIN TRANSACTION;&lt;/code&gt; and &lt;code&gt;COMMIT;&lt;/code&gt; lines. Bunny Database runs the whole paste as one transaction and refuses a paste that opens its own. Then open the Run menu and choose Run All Statements:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F85mv92x851gv6hs26mg3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F85mv92x851gv6hs26mg3.png" alt=" " width="799" height="438"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The tables appear in the sidebar once the run finishes. Check a few row counts against your val:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="nb"&gt;COUNT&lt;/span&gt;&lt;span class="cm"&gt;(*) FROM users;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Rehearse on a throwaway database first, and pause writes on the val during the final copy so only one database accepts writes at a time. A very large dump can be awkward to paste into a browser, so the CLI section below shows how to import it from a file.&lt;/p&gt;

&lt;p&gt;Bunny Database is in Public Preview, so features and APIs may still change.&lt;/p&gt;

&lt;h2&gt;
  
  
  Move the blobs
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Create the storage zone with S3 switched on
&lt;/h3&gt;

&lt;p&gt;Create a storage zone in the dashboard under Storage, and switch on S3 compatibility in the same form. S3 access can only be enabled when the zone is created, and the copy step below uses it. Pick Falkenstein (DE) as the main region to match the helper, or change &lt;code&gt;StorageRegion.Falkenstein&lt;/code&gt; to the region you choose.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Foqbrqg4f9xayrtq085bf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Foqbrqg4f9xayrtq085bf.png" alt=" " width="800" height="943"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fs49vnlzhtvm3zpwx4cj3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fs49vnlzhtvm3zpwx4cj3.png" alt=" " width="800" height="826"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Open the zone's FTP &amp;amp; API Access tab and copy its password.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fqi6t6aeam0r26xwfl2v1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fqi6t6aeam0r26xwfl2v1.png" alt=" " width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In your script's Environment page, add &lt;code&gt;BUNNY_STORAGE_ZONE&lt;/code&gt; with the zone's name and &lt;code&gt;BUNNY_STORAGE_PASSWORD&lt;/code&gt; as a secret with the password.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fgfmbbhxci9l59gyz488h.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fgfmbbhxci9l59gyz488h.png" alt=" " width="799" height="502"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Download your blobs from Val Town
&lt;/h3&gt;

&lt;p&gt;Existing blobs need copying while Val Town still serves them. Both scripts below write every blob into a local &lt;code&gt;./blobs&lt;/code&gt; folder, which also doubles as a backup.&lt;/p&gt;

&lt;p&gt;New vals import &lt;code&gt;std/blob/main.ts&lt;/code&gt;, which keeps blobs scoped to the val. Your account API token can't see those, so &lt;code&gt;vt.blobs.list()&lt;/code&gt; from the Val Town SDK comes back empty. The val itself can read them, so add a temporary HTTP file to the val that lists the keys and returns one blob at a time:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// blob-export.ts (delete it once the copy is verified)&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;blob&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"https://esm.town/v/std/blob/main.ts"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Request&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Response&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;token&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Deno&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"BLOB_EXPORT_TOKEN"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;token&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"authorization"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="sb"&gt;`Bearer ${token}`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Response&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Unauthorized"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;401&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="no"&gt;URL&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;searchParams&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"key"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;Response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;blob&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;list&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Response&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;blob&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s2"&gt;"cache-control"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"no-store"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Set &lt;code&gt;BLOB_EXPORT_TOKEN&lt;/code&gt; to a long random string in the val's environment variables, then pull everything down with Node:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// download-blobs.mjs&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;mkdir&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;writeFile&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"node:fs/promises"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;dirname&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;join&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"node:path"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;BLOB_EXPORT_URL&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;headers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nc"&gt;Authorization&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sb"&gt;`Bearer ${process.env.BLOB_EXPORT_TOKEN}`&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nb"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;headers&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nb"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sb"&gt;`${url}?key=${encodeURIComponent(key)}`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;headers&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ok&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sb"&gt;`${key}: ${res.status}`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;path&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"blobs"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;mkdir&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;dirname&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;recursive&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;writeFile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Buffer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;arrayBuffer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;BLOB_EXPORT_URL&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;https://your-blob-export.web.val.run \
&lt;span class="nv"&gt;BLOB_EXPORT_TOKEN&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;your-token \
node download-blobs.mjs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Older vals that import &lt;code&gt;std/blob&lt;/code&gt; without &lt;code&gt;main.ts&lt;/code&gt; use account-wide storage, which your API token can read directly. Create a token in your Val Town settings, export it as &lt;code&gt;VAL_TOWN_API_KEY&lt;/code&gt;, and run this version instead:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// download-global-blobs.mjs&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;ValTown&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"@valtown/sdk"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;mkdir&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;writeFile&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"node:fs/promises"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;dirname&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;join&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"node:path"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;vt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;ValTown&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// reads VAL_TOWN_API_KEY&lt;/span&gt;

&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;vt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;blobs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;list&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;vt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;blobs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;path&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"blobs"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;mkdir&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;dirname&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;recursive&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;writeFile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Buffer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;arrayBuffer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm install @valtown/sdk
node download-global-blobs.mjs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Copy them into Bunny Storage
&lt;/h3&gt;

&lt;p&gt;Open the storage zone's File manager in the dashboard. Then open your local &lt;code&gt;blobs&lt;/code&gt; folder, select everything inside it, and drag the selection onto the file manager.&lt;/p&gt;

&lt;p&gt;Drag the contents. Each blob key has to sit at the root of the zone, so &lt;code&gt;config&lt;/code&gt; lands at &lt;code&gt;/config&lt;/code&gt;, which is the path &lt;code&gt;blob.get("config")&lt;/code&gt; asks for:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Foxiinwgas1ymhy7b3kes.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Foxiinwgas1ymhy7b3kes.png" alt=" " width="800" height="456"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The upload keeps nested keys as folders, so &lt;code&gt;users/1/profile&lt;/code&gt; arrives as a &lt;code&gt;users&lt;/code&gt; folder holding &lt;code&gt;1/profile&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fq4xdcgaeu9cjohzjjju8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fq4xdcgaeu9cjohzjjju8.png" alt=" " width="800" height="716"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For a val with thousands of blobs, rclone copies the whole folder in one command through the zone's S3 API. The endpoint uses your zone's region code in lowercase, so a zone in Falkenstein (DE) uses &lt;code&gt;https://de-s3.storage.bunnycdn.com&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;rclone config create bunny s3 \
  &lt;span class="nv"&gt;provider&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;Other \
  &lt;span class="nv"&gt;access_key_id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;my-zone \
  &lt;span class="nv"&gt;secret_access_key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;your-storage-password \
  &lt;span class="nv"&gt;endpoint&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;https://de-s3.storage.bunnycdn.com

rclone copy ./blobs bunny:my-zone
rclone ls bunny:my-zone
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The access key is the zone's name and the secret is the zone password you copied earlier. &lt;code&gt;rclone copy ./blobs&lt;/code&gt; copies what's inside the folder, so the keys land at the root here too.&lt;/p&gt;

&lt;h2&gt;
  
  
  Publish and switch over
&lt;/h2&gt;

&lt;p&gt;Add an environment variable or secret for any other value the val read with &lt;code&gt;Deno.env.get()&lt;/code&gt;, then click Publish in the code editor. Watch the live logs while you send a few test requests, and compare each response with the same route on your &lt;code&gt;val.run&lt;/code&gt; URL.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F5ub38ixgyl9pv8aaxek0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F5ub38ixgyl9pv8aaxek0.png" alt=" " width="799" height="438"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A val that has grown into a proper project fits better in a GitHub repository, where each push deploys through GitHub Actions. The repository becomes the place you edit the code from then on.&lt;/p&gt;

&lt;p&gt;Val Town's docs also cover &lt;a href="https://docs.val.town/migration/redirects" rel="noopener noreferrer"&gt;redirecting &lt;code&gt;val.run&lt;/code&gt; URLs&lt;/a&gt;, which saves updating every webhook and bookmark by hand. Steve personally committed to the URL redirects for 10 years, which is great peace of mind for those migrating who have URLs out there that others rely on &amp;lt;3&lt;/p&gt;

&lt;h2&gt;
  
  
  Prefer the terminal?
&lt;/h2&gt;

&lt;p&gt;The &lt;a href="https://bunny.net/docs/cli/commands/db" rel="noopener noreferrer"&gt;bunny.net CLI&lt;/a&gt; runs the same migration from a folder holding your &lt;code&gt;main.ts&lt;/code&gt;, the Val Town &lt;code&gt;dump.sql&lt;/code&gt;, and the &lt;code&gt;./blobs&lt;/code&gt; folder. Install it and sign in first:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm install -g @bunny.net/cli
bunny login
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create the script, then the database. &lt;code&gt;--save-env&lt;/code&gt; writes the database credentials to a local &lt;code&gt;.env&lt;/code&gt; file, and the import reads the dump from a file, so large databases are fine here:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;bunny scripts create my-val --type standalone
bunny db create --name my-val --link --token --save-env

grep -v &lt;span class="s1"&gt;'^BEGIN TRANSACTION;$\|^COMMIT;$'&lt;/span&gt; dump.sql &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; app.sql
bunny db shell app.sql
bunny db shell -e &lt;span class="s2"&gt;"SELECT COUNT(*) FROM users"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;.env&lt;/code&gt; file stays on your machine, so hand the two values to the script as secrets:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;source&lt;/span&gt; .env
bunny scripts env &lt;span class="nb"&gt;set&lt;/span&gt; BUNNY_DATABASE_URL &lt;span class="s2"&gt;"$BUNNY_DATABASE_URL"&lt;/span&gt; --secret
bunny scripts env &lt;span class="nb"&gt;set&lt;/span&gt; BUNNY_DATABASE_AUTH_TOKEN &lt;span class="s2"&gt;"$BUNNY_DATABASE_AUTH_TOKEN"&lt;/span&gt; --secret
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create the storage zone with S3 switched on, and let the CLI write the rclone remote for you. The remote is named after the zone:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;bunny storage zones create my-zone --region DE --s3
bunny storage zones credentials my-zone --format rclone &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; ~/.config/rclone/rclone.conf
rclone copy ./blobs my-zone:my-zone
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run &lt;code&gt;bunny storage zones credentials my-zone --show-secret&lt;/code&gt; to see the zone's password, then give the script its storage settings and deploy:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;bunny scripts env &lt;span class="nb"&gt;set&lt;/span&gt; BUNNY_STORAGE_ZONE my-zone
bunny scripts env &lt;span class="nb"&gt;set&lt;/span&gt; BUNNY_STORAGE_PASSWORD your-storage-password --secret
bunny scripts deploy main.ts
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The CLI uploads &lt;code&gt;main.ts&lt;/code&gt; as it stands, so the dashboard's code editor shows the same file and you can keep editing it there.&lt;/p&gt;

&lt;h2&gt;
  
  
  Hand the port to your coding agent
&lt;/h2&gt;

&lt;p&gt;Working through the steps by hand is a good way to learn each bunny.net product. You can also hand the whole job to Claude Code, Cursor, or Codex. Copy your val's files into a folder, save the Dump as SQL output next to them as &lt;code&gt;dump.sql&lt;/code&gt;, and give the agent the bunny.net CLI skill so it knows the commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;bunny login
bunny skills install
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then paste this prompt:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Port the Val Town val in this folder to bunny.net. Follow these rules exactly.

Code
- Produce one standalone Edge Script file, main.ts, with no build step.
- Import every package with an npm: specifier, e.g. "npm:hono",
  "npm:@bunny.net/edgescript-sdk". Bare package names fail without a bundler.
- Replace `export default handler` with BunnySDK.net.http.serve(handler).
  For Hono, pass app.fetch.
- Replace Deno.env.get("X") with process.env.X, importing process from
  "node:process".
- Replace std/sqlite with a libSQL client named `sqlite`, so call sites stay
  the same:
    import { createClient } from "npm:@libsql/client/web";
    const sqlite = createClient({
      url: process.env.BUNNY_DATABASE_URL!,
      authToken: process.env.BUNNY_DATABASE_AUTH_TOKEN!,
    });
- Replace std/blob with a `blob` object built on "npm:@bunny.net/storage-sdk",
  connecting with BUNNY_STORAGE_ZONE and BUNNY_STORAGE_PASSWORD. Implement
  only the methods the val uses (get, set, getJSON, setJSON, delete).
  getJSON must return undefined for a missing key. Bunny Storage lists one
  folder at a time, so write a recursive list only if the val calls
  blob.list.
- Replace any other esm.town import with the npm or JSR package it wraps.

Script and database
- bunny scripts create &amp;lt;val-name&amp;gt; --type standalone
- Strip the transaction lines from dump.sql, because Bunny Database runs
  each file in one transaction and rejects a file that opens its own:
    grep -v '^BEGIN TRANSACTION;$\|^COMMIT;$' dump.sql &amp;gt; app.sql
- Create an empty database and import:
    bunny db create --name &amp;lt;val-name&amp;gt; --primary FR --link --token --save-env
    bunny db shell app.sql
- Run SELECT COUNT(*) on every table and show me the results.
- Copy BUNNY_DATABASE_URL and BUNNY_DATABASE_AUTH_TOKEN from .env to the
  script with bunny scripts env set &amp;lt;NAME&amp;gt; &amp;lt;value&amp;gt; --secret.

Blobs
- If the val imports std/blob/main.ts, its blobs are scoped to the val and
  the Val Town API token can't list them. Write a temporary, bearer-token
  protected blob-export.ts for me to add to the val, which returns
  blob.list() with no query string and one blob's body for ?key=. Then
  download every key into ./blobs.
- If it imports std/blob without main.ts, download every key into ./blobs
  with vt.blobs.list() and vt.blobs.get(key) from @valtown/sdk.
- Create an S3-enabled storage zone and copy the files:
    bunny storage zones create &amp;lt;zone&amp;gt; --region DE --s3
    bunny storage zones credentials &amp;lt;zone&amp;gt; --format rclone &amp;gt;&amp;gt; ~/.config/rclone/rclone.conf
    rclone copy ./blobs &amp;lt;zone&amp;gt;:&amp;lt;zone&amp;gt;
- Set BUNNY_STORAGE_ZONE, and BUNNY_STORAGE_PASSWORD with --secret.

Deploy
- Set any other environment variable the val reads, using --secret for
  tokens and passwords. Never print a secret in your output.
- bunny scripts deploy main.ts
- Request each GET route on the val.run URL and the bunny.run URL, and show
  me any response that differs. Ask before sending anything that writes.

Ask me before creating anything on bunny.net, and never delete or change
data on Val Town.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Your agent should stop and ask you to add &lt;code&gt;blob-export.ts&lt;/code&gt; to the val, and to approve each bunny.net resource it wants to create.&lt;/p&gt;

&lt;p&gt;Your script now sits on the same account as the rest of the bunny.net platform. &lt;a href="https://bunny.net/blog/were-making-bunny-dns-free/" rel="noopener noreferrer"&gt;Bunny DNS is free&lt;/a&gt; for up to 500 domains with no query fees, so you can host the domain your old val answered on and point it at the script, and you aren't limited to one script. The pull zone in front of your script is &lt;a href="https://bunny.net/cdn/" rel="noopener noreferrer"&gt;Bunny CDN&lt;/a&gt;, and &lt;a href="https://bunny.net/shield/" rel="noopener noreferrer"&gt;Bunny Shield&lt;/a&gt;, &lt;a href="https://bunny.net/optimizer/" rel="noopener noreferrer"&gt;Bunny Optimizer&lt;/a&gt;, &lt;a href="https://bunny.net/stream/" rel="noopener noreferrer"&gt;Bunny Stream&lt;/a&gt;, and &lt;a href="https://bunny.net/magic-containers/" rel="noopener noreferrer"&gt;Magic Containers&lt;/a&gt; are there when a small project grows into something bigger.&lt;/p&gt;

&lt;p&gt;If something in your migration doesn't behave, come and ask in the &lt;a href="https://discord.com/invite/bunnynet" rel="noopener noreferrer"&gt;bunny.net Discord&lt;/a&gt;. We'd like to hear which vals you're bringing over, and if any would make good templates for others, reach out and I'll get them added.&lt;/p&gt;

</description>
      <category>tutorial</category>
      <category>serverless</category>
      <category>database</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Build and deploy scripts at the edge with the bunny.net CLI</title>
      <dc:creator>Jamie Barton</dc:creator>
      <pubDate>Thu, 12 Nov 2026 11:54:11 +0000</pubDate>
      <link>https://dev.to/bunnydotnet/build-and-deploy-scripts-at-the-edge-with-the-bunnynet-cli-5ajn</link>
      <guid>https://dev.to/bunnydotnet/build-and-deploy-scripts-at-the-edge-with-the-bunnynet-cli-5ajn</guid>
      <description>&lt;p&gt;&lt;em&gt;Originally published at bunny.net on June 10, 2026. Since then, the bunny.net CLI has expanded beyond Bunny Database and Edge Scripting. Find out more &lt;a href="https://bunny.net/docs/cli" rel="noopener noreferrer"&gt;in the docs&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;A few weeks ago we &lt;a href="https://bunny.net/blog/introducing-the-bunny-net-cli/" rel="noopener noreferrer"&gt;introduced the bunny.net CLI&lt;/a&gt;, one command-line tool for managing your entire bunny.net stack. That first release shipped with full Database support, and we promised more would follow.&lt;/p&gt;

&lt;p&gt;Today, &lt;strong&gt;&lt;a href="https://docs.bunny.net/scripting" rel="noopener noreferrer"&gt;Edge Scripting&lt;/a&gt;&lt;/strong&gt; lands in the CLI.&lt;/p&gt;

&lt;p&gt;You can scaffold a new script from a template, develop and test it locally with Node or Deno, deploy a built bundle to the global network, manage environment variables, and step through deployment history from your terminal.&lt;/p&gt;

&lt;h2&gt;
  
  
  A two-minute tour
&lt;/h2&gt;

&lt;p&gt;If you've already got the CLI installed and you're logged in, three commands will get you to a deployed function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;bunny scripts init --name my-edge-app --type standalone --template &lt;span class="s2"&gt;"Return JSON"&lt;/span&gt; --deploy
&lt;span class="nb"&gt;cd&lt;/span&gt; my-edge-app
npm run build
bunny scripts deploy dist/index.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you haven't installed the CLI yet, do that first:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm install -g @bunny.net/cli
bunny login
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Scaffold a project from a template
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;bunny scripts init&lt;/code&gt; creates a new edge script project on your machine. Run it with no flags and the CLI walks you through it interactively, asking you to pick a template, name the project, and choose whether to install dependencies:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;bunny scripts init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also pass everything as flags, which is handy when you're in a hurry or when an agent is driving:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;bunny scripts init \
  --name my-edge-app \
  --type standalone \
  --template &lt;span class="s2"&gt;"Return JSON"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add &lt;code&gt;--deploy&lt;/code&gt; to also create the remote script on bunny.net and link the directory in the same step. Without it, &lt;code&gt;init&lt;/code&gt; only scaffolds the local project, and you create the remote script later with &lt;code&gt;bunny scripts create&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The built-in templates are &lt;code&gt;Empty&lt;/code&gt;, &lt;code&gt;Return JSON&lt;/code&gt;, and &lt;code&gt;Simple Middleware&lt;/code&gt;. Each one comes with a working project layout and sensible defaults so you can build and deploy straight away.&lt;/p&gt;

&lt;p&gt;You can also bring your own template from a Git repo:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;bunny scripts init --name my-edge-app --repo user/my-template
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Custom templates always prompt before installing dependencies, since a template's install scripts run on your machine. Review the repo before you let it install.&lt;/p&gt;

&lt;h2&gt;
  
  
  Run it locally
&lt;/h2&gt;

&lt;p&gt;Edge Scripts are JavaScript and TypeScript projects built on Web-standard APIs. You develop them locally with your own editor and the debugging tools you already use.&lt;/p&gt;

&lt;p&gt;The CLI auto-detects your package manager from the template's lockfile (bun, npm, pnpm, or yarn) and uses the template's own dev and build scripts:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd&lt;/span&gt; my-edge-app
npm install
npm run dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The CLI doesn't yet ship a custom runtime emulator. It wraps the tools you'd reach for anyway, so local development stays fast and predictable.&lt;/p&gt;

&lt;h2&gt;
  
  
  Link a directory to a script
&lt;/h2&gt;

&lt;p&gt;Once you've got something you want to deploy, connect the working directory to a script on bunny.net:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;bunny scripts link
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run it once, and it writes a small &lt;code&gt;.bunny/script.json&lt;/code&gt; manifest into your project that records which script on bunny.net this directory belongs to. From that point on, every other &lt;code&gt;scripts&lt;/code&gt; command knows what you're targeting:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;bunny scripts deploy&lt;/code&gt; deploys this project&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;bunny scripts env set API_KEY=...&lt;/code&gt; writes to this script's environment&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;bunny scripts deployments list&lt;/code&gt; shows this script's history&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The script ID stays out of your shell history, and you don't pass it on every command. Run &lt;code&gt;bunny scripts link&lt;/code&gt; with no flags to choose from a list, or &lt;code&gt;bunny scripts link --id 12345&lt;/code&gt; to link directly.&lt;/p&gt;

&lt;p&gt;The manifest holds per-developer state, so it shouldn't be committed. &lt;code&gt;bunny scripts init&lt;/code&gt; adds &lt;code&gt;.bunny/&lt;/code&gt; to your &lt;code&gt;.gitignore&lt;/code&gt; automatically. If you ran &lt;code&gt;bunny scripts link&lt;/code&gt; or &lt;code&gt;bunny scripts create&lt;/code&gt; in an existing repo, add &lt;code&gt;.bunny/&lt;/code&gt; to &lt;code&gt;.gitignore&lt;/code&gt; yourself, then anyone who clones the repo links their own script.&lt;/p&gt;

&lt;p&gt;For those deploying scripts in CI, you can skip the project linking by passing the Edge Script ID when you deploy:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;bunny scripts deploy dist/index.js 12345
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Build and deploy
&lt;/h2&gt;

&lt;p&gt;Edge Scripts deploy as a single built bundle. The CLI doesn't build for you, so run the template's own build step first, then point deploy at the output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm run build
bunny scripts deploy dist/index.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;deploy&lt;/code&gt; uploads the file as a new release and publishes it live by default. On success it prints the script's live hostname:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;✓ Published my-edge-app
  https://my-edge-app.bunny.run
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you want to upload a release without publishing it, stage it with &lt;code&gt;--skip-publish&lt;/code&gt; and publish later.&lt;/p&gt;

&lt;h2&gt;
  
  
  Put it on your own domain
&lt;/h2&gt;

&lt;p&gt;Every script gets a &lt;code&gt;bunny.run&lt;/code&gt; URL, but you can also bring your own domain. We've made it super easy with a new command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;bunny scripts domains add shop.example.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;bunny scripts domains add&lt;/code&gt; sets up HTTPS on your own domain. bunny.net issues SSL certificates for free and can do so as soon as your DNS points to the network, so the command prints the exact CNAME record to create, along with the follow-up command to run. Once DNS has propagated, request your certificate:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;bunny scripts domains ssl shop.example.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;HTTPS is enforced by default, so anyone arriving over &lt;code&gt;http://&lt;/code&gt; is redirected.&lt;/p&gt;

&lt;p&gt;List a script's domains any time to check their SSL status:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;bunny scripts domains list
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Manage environment variables and secrets
&lt;/h2&gt;

&lt;p&gt;Most edge functions need configuration values like API tokens, feature flags, or region hints. The CLI handles two kinds. Plain &lt;strong&gt;variables&lt;/strong&gt; are stored on bunny.net and can be read back. &lt;strong&gt;Secrets&lt;/strong&gt; are encrypted, and their values can never be read back once set:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;bunny scripts env &lt;span class="nb"&gt;set&lt;/span&gt; DATABASE_URL &lt;span class="s2"&gt;"libsql://..."&lt;/span&gt;
bunny scripts env &lt;span class="nb"&gt;set&lt;/span&gt; API_KEY &lt;span class="s2"&gt;"sk_..."&lt;/span&gt; --secret
bunny scripts env list
bunny scripts env remove API_KEY
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Names are uppercased automatically, and a name can be a variable or a secret but not both. &lt;code&gt;env list&lt;/code&gt; shows secret values as blank, since the API never returns them.&lt;/p&gt;

&lt;p&gt;To pull plain variables into a local file for development, use &lt;code&gt;env pull&lt;/code&gt;. It writes &lt;code&gt;NAME=VALUE&lt;/code&gt; lines to &lt;code&gt;.bunny/.env&lt;/code&gt;. Secrets are never included, so keep their source values somewhere safe:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;bunny scripts env pull
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Listing supports &lt;code&gt;--output json&lt;/code&gt;, useful for diffing or syncing with another tool:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;bunny scripts env list --output json &lt;span class="o"&gt;|&lt;/span&gt; jq &lt;span class="s1"&gt;'.[].name'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Deployment history
&lt;/h2&gt;

&lt;p&gt;Every release is recorded, and the CLI gives you a view into that history:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;bunny scripts deployments list
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ID       Status      Author   Released   Published
14021    ● Live      jamie    2m ago     yes
14008    ○ Archived  jamie    1h ago     yes
13990    ○ Archived  jamie    1d ago     yes
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The live release is marked with a filled dot, and archived releases are marked with an open one. If a release is live and the script has a linked pull zone, the hostname is printed at the end.&lt;/p&gt;

&lt;p&gt;Need to roll back? You don't have to rebuild anything. The bundle for every past release is already on bunny.net, so grab the ID of a known-good one from that list and republish it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;bunny scripts deployments publish 13990
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This flips which release is live without re-uploading anything, so a bad deploy can be undone in seconds. &lt;code&gt;deploy&lt;/code&gt; ships new code. &lt;code&gt;publish&lt;/code&gt; re-promotes a release that has already shipped.&lt;/p&gt;

&lt;h2&gt;
  
  
  See how it's doing
&lt;/h2&gt;

&lt;p&gt;Once a script is serving traffic, you'll want to know how much traffic it's handling and what it's costing. &lt;code&gt;bunny scripts stats&lt;/code&gt; pulls request, CPU, and cost totals for the script and draws a per-day bar chart of requests served right in your terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;bunny scripts stats

Key                   Value
Script                bunny-cards
Period                last 30 days
Total Requests        1,455
Total CPU             43,336ms
Avg CPU / Execution   29.78ms
Total Cost            $0.00

Requests served
May 18, 2026  ░░░░░░░░░░░░░░░░░░░░░░░░    0
May 19, 2026  ████████████████████████  504
May 20, 2026  ██████████████████░░░░░░  383
May 21, 2026  ░░░░░░░░░░░░░░░░░░░░░░░░    0
May 22, 2026  ░░░░░░░░░░░░░░░░░░░░░░░░    0
May 23, 2026  ░░░░░░░░░░░░░░░░░░░░░░░░    0
May 24, 2026  ░░░░░░░░░░░░░░░░░░░░░░░░    0
May 25, 2026  █░░░░░░░░░░░░░░░░░░░░░░░    4
May 26, 2026  ░░░░░░░░░░░░░░░░░░░░░░░░    0
May 27, 2026  █░░░░░░░░░░░░░░░░░░░░░░░    5
May 28, 2026  ██░░░░░░░░░░░░░░░░░░░░░░   37
May 29, 2026  ████░░░░░░░░░░░░░░░░░░░░   90
May 30, 2026  ░░░░░░░░░░░░░░░░░░░░░░░░    0
May 31, 2026  ░░░░░░░░░░░░░░░░░░░░░░░░    0
Jun 1, 2026   ░░░░░░░░░░░░░░░░░░░░░░░░    0
Jun 2, 2026   ░░░░░░░░░░░░░░░░░░░░░░░░    0
Jun 3, 2026   ░░░░░░░░░░░░░░░░░░░░░░░░    0
Jun 4, 2026   ███████████░░░░░░░░░░░░░  223
Jun 5, 2026   █████████░░░░░░░░░░░░░░░  191
Jun 6, 2026   █░░░░░░░░░░░░░░░░░░░░░░░   11
Jun 7, 2026   █░░░░░░░░░░░░░░░░░░░░░░░    5
Jun 8, 2026   █░░░░░░░░░░░░░░░░░░░░░░░    2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By default, it covers the last 30 days. Narrow the window with &lt;code&gt;--from&lt;/code&gt; and &lt;code&gt;--to&lt;/code&gt;, or switch to an hourly breakdown when you're chasing a spike:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;bunny scripts stats --from 2026-05-01 --to 2026-05-31
bunny scripts stats --hourly
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Like everything else, it uses your linked script when you don't pass an ID, and &lt;code&gt;--output json&lt;/code&gt; gives you the data to pipe into whatever you use to track usage.&lt;/p&gt;

&lt;h2&gt;
  
  
  Works with your agent and CI
&lt;/h2&gt;

&lt;p&gt;Prompts and spinners are TTY-aware, so they disappear in CI. Commands support &lt;code&gt;--output json&lt;/code&gt;, and destructive commands like &lt;code&gt;delete&lt;/code&gt; and &lt;code&gt;env remove&lt;/code&gt; take &lt;code&gt;--force&lt;/code&gt; so they don't block on a confirmation prompt in a pipeline.&lt;/p&gt;

&lt;p&gt;In CI you can skip the global install and run the CLI through &lt;code&gt;npx&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="c1"&gt;# .github/workflows/deploy.yml
&lt;/span&gt;&lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;npm ci&lt;/span&gt;
&lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;npm run build&lt;/span&gt;
&lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;npx @bunny.net/cli scripts deploy dist/index.js ${{ secrets.SCRIPT_ID }}&lt;/span&gt;
  &lt;span class="na"&gt;env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;BUNNYNET_API_KEY&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ secrets.BUNNYNET_API_KEY }}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When you scaffold with &lt;code&gt;bunny scripts init --deploy&lt;/code&gt;, the command prints the &lt;code&gt;SCRIPT_ID&lt;/code&gt; to add as a repo secret, so CI deploys to the right script without committing the link manifest.&lt;/p&gt;

&lt;p&gt;AI coding assistants use the CLI directly, either from a global install or through &lt;code&gt;npx @bunny.net/cli&lt;/code&gt;. We ship Edge Scripting skills alongside it, so Claude Code, Cursor, Windsurf, or any agent that runs shell commands can scaffold a project, link it, set environment variables, and deploy.&lt;/p&gt;

&lt;h2&gt;
  
  
  What's next
&lt;/h2&gt;

&lt;p&gt;Edge Scripting joins Bunny Database in the CLI today. Storage, Magic Containers, and the rest of the bunny.net stack are coming next.&lt;/p&gt;

&lt;p&gt;Get started and create your first Edge Script with the bunny.net CLI:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm install -g @bunny.net/cli
bunny login
bunny scripts init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The CLI is open source and developed in public. If something's broken, &lt;a href="https://github.com/BunnyWay/cli/issues" rel="noopener noreferrer"&gt;open an issue&lt;/a&gt;. If you want to share what you've built, find us in &lt;a href="https://discord.com/invite/bunnynet" rel="noopener noreferrer"&gt;Discord&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>devops</category>
      <category>cli</category>
      <category>serverless</category>
    </item>
    <item>
      <title>Introducing the bunny.net CLI</title>
      <dc:creator>Jamie Barton</dc:creator>
      <pubDate>Mon, 09 Nov 2026 14:29:05 +0000</pubDate>
      <link>https://dev.to/bunnydotnet/introducing-the-bunnynet-cli-59np</link>
      <guid>https://dev.to/bunnydotnet/introducing-the-bunnynet-cli-59np</guid>
      <description>&lt;p&gt;&lt;em&gt;Originally published at bunny.net on May 11, 2026. Since then, the bunny.net CLI has expanded beyond Bunny Database. Find out more &lt;a href="https://bunny.net/docs/cli" rel="noopener noreferrer"&gt;in the docs&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The best developer tools don't ask you to context-switch. They meet you where you already are.&lt;/p&gt;

&lt;p&gt;For most developers, that's the terminal. Not because it's retro or minimal, but because it's the one surface that works everywhere—your local machine, your CI pipeline, your AI coding assistant. The commands you type are the same commands your automation runs. A good CLI isn't just a power-user shortcut. It's the most composable interface a platform can offer.&lt;/p&gt;

&lt;p&gt;Today we're releasing the bunny.net CLI, a single command-line tool for building and managing your entire bunny.net stack. This first release ships with full Database support, including the interactive SQL shell we introduced a few weeks ago. Support for Edge Scripting, Storage, Magic Containers, and more is coming soon.&lt;/p&gt;

&lt;p&gt;The CLI is currently in public preview, and we’re building it in the open. We’d love your feedback, bug reports, and pull requests as we shape what comes next.&lt;/p&gt;

&lt;h2&gt;
  
  
  Up and running in three commands
&lt;/h2&gt;

&lt;p&gt;Install with npm:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install -g @bunny.net/cli

# or
# curl -fsSL https://cli.bunny.net/install.sh | sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Log in:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;bunny login
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This opens your browser, authenticates with your bunny.net account, and saves a profile locally. Note that it currently fetches your API key from your account once signed in.&lt;/p&gt;

&lt;p&gt;Confirm it worked:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;bunny whoami
Logged in as Jamie Barton (jamie@bunny.net) 🐇
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fquab2ozg7ss7bib3g0ox.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fquab2ozg7ss7bib3g0ox.png" alt=" " width="799" height="649"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Database management without the dashboard detour
&lt;/h2&gt;

&lt;p&gt;The usual flow after creating a database is to open a dashboard, hunt for the connection string, copy it, paste it somewhere, hope you got the right one.&lt;/p&gt;

&lt;p&gt;The CLI replaces all of that with a few commands.&lt;/p&gt;

&lt;h3&gt;
  
  
  Create a database
&lt;/h3&gt;

&lt;p&gt;Run &lt;code&gt;bunny db create&lt;/code&gt; with no arguments and the CLI walks you through it interactively — name, region, options:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;bunny db create
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Already know what you want? Pass the flags directly:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;bunny db create &lt;span class="nt"&gt;--name&lt;/span&gt; my-app-db &lt;span class="nt"&gt;--primary&lt;/span&gt; UK
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Both paths produce the same result. Interactive mode is great for exploring. Flags-first is what you'll reach for in scripts, pipelines, or when your AI assistant is driving.&lt;/p&gt;

&lt;p&gt;After creation, the CLI offers to link the database to your current directory, generate an auth token, and write credentials to &lt;code&gt;.env&lt;/code&gt;  so you can go straight from &lt;code&gt;create&lt;/code&gt; to querying in the same shell session.&lt;/p&gt;

&lt;p&gt;Inspect what you just created:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;bunny db show

 Key               Value
 ID                db_01KP8D0MKHB7HWEYYE6VX8CTG7
 Name              my-app-db
 URL               libsql://01KP8D0MGVG0PEWR9SCTND02PH-my-app-db.lite.bunnydb.net/
 Status            Active    
 Size              4.1 KB / 1024.0 MB  ░░░░░░░░░░░░░░░░░░░░  0%
 Storage Region    eu-west-1                   
 Primary Region    London &lt;span class="o"&gt;(&lt;/span&gt;UK&lt;span class="o"&gt;)&lt;/span&gt;
 Replica Regions   None
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Linking a directory to a database
&lt;/h3&gt;

&lt;p&gt;Most &lt;code&gt;db&lt;/code&gt; commands need to know which database you're targeting. Passing an ID every time gets old fast, so the CLI resolves the target database automatically in this order:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;An explicit &lt;code&gt;&amp;lt;database-id&amp;gt;&lt;/code&gt; argument&lt;/li&gt;
&lt;li&gt;A &lt;code&gt;.bunny/database.json&lt;/code&gt; manifest created by &lt;code&gt;bunny db link&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;BUNNY_DATABASE_URL&lt;/code&gt; from a &lt;code&gt;.env&lt;/code&gt; file (walked up from the current directory)&lt;/li&gt;
&lt;li&gt;An interactive picker if none of the above match&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The recommended flow is &lt;code&gt;bunny db link&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;bunny db &lt;span class="nb"&gt;link&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This writes a small &lt;code&gt;.bunny/database.json&lt;/code&gt; manifest to your project. Every &lt;code&gt;db&lt;/code&gt; command run from that directory (&lt;code&gt;show&lt;/code&gt;, &lt;code&gt;shell&lt;/code&gt;, &lt;code&gt;studio&lt;/code&gt;, &lt;code&gt;usage&lt;/code&gt;, &lt;code&gt;tokens create&lt;/code&gt;) now knows which database to target. No flags, no env var lookups, no connection strings in your shell history.&lt;/p&gt;

&lt;p&gt;Add &lt;code&gt;.bunny/&lt;/code&gt; to your &lt;code&gt;.gitignore&lt;/code&gt;. The manifest is a per-developer convenience, not something to commit. Each contributor links their own environment.&lt;/p&gt;

&lt;p&gt;If you'd rather drive things from &lt;code&gt;.env&lt;/code&gt; (handy when the same &lt;code&gt;BUNNY_DATABASE_URL&lt;/code&gt; is already wired into your app), the CLI picks that up automatically. And when you need to run a one-off command against a different database without changing context, pass the ID as an argument:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;bunny db show db_01KP8D0MKHB7HWEYYE6VX8CTG7
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  List, monitor, and clean up
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;bunny db list
bunny db delete
bunny db usage
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Multi-region replication
&lt;/h3&gt;

&lt;p&gt;Bring data closer to your users with read replicas:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;bunny db regions list
bunny db regions add &lt;span class="nt"&gt;--replicas&lt;/span&gt; UK,NY
bunny db regions remove &lt;span class="nt"&gt;--replicas&lt;/span&gt; NY
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Token management
&lt;/h3&gt;

&lt;p&gt;Generate and revoke database tokens without touching the dashboard:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;bunny db tokens create
bunny db tokens create &lt;span class="nt"&gt;--read-only&lt;/span&gt; &lt;span class="nt"&gt;--expiry&lt;/span&gt; 30d
bunny db tokens invalidate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Drop into the interactive shell
&lt;/h3&gt;

&lt;p&gt;The CLI embeds the same @bunny.net/database-shell we released as a standalone package, so you get the full interactive experience (dot-commands, saved views, output modes, sensitive column masking) with zero extra setup:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;bunny db shell
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;✓ Connected to database
  Type .help for commands, .quit to exit.

→  SELECT id, name, email FROM users;
┌────┬───────────┬─────────────────────┐
│ id │ name      │ email               │
├────┼───────────┼─────────────────────┤
│ 1  │ Alice     │ a****e@example.com  │
│ 2  │ Bob       │ b****b@example.com  │
└────┴───────────┴─────────────────────┘
2 rows (4ms)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;No connection strings. No token flags. Your authenticated profile handles it. Just &lt;code&gt;bunny db shell&lt;/code&gt; and you're querying.&lt;/p&gt;

&lt;p&gt;Run a one-off query without entering the REPL:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;bunny db shell &amp;lt;database-id&amp;gt; &lt;span class="s2"&gt;"SELECT count(*) FROM orders"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  A read-only view with &lt;code&gt;bunny db studio&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;Sometimes you don't want a REPL. You want to click through tables and see what's actually in there. &lt;code&gt;bunny db studio&lt;/code&gt; spins up a local server and opens a read-only table viewer in your browser:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;bunny db studio
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It uses the same resolution order as every other &lt;code&gt;db&lt;/code&gt; command, so if you've run &lt;code&gt;bunny db link&lt;/code&gt; it picks up the right database automatically. A short-lived auth token is generated for the session and discarded when you close it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fy7xgrj102udw6xr55rp9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fy7xgrj102udw6xr55rp9.png" alt=" " width="800" height="437"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Studio is currently experimental and read-only by design, &lt;strong&gt;inspect, don't mutate&lt;/strong&gt;. For schema changes and data edits, reach for &lt;code&gt;bunny db shell&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Raw API access with &lt;code&gt;bunny api&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;Purpose-built commands cover the most common workflows, but sometimes you need to reach an endpoint that doesn’t have a dedicated command yet, or you just want to poke at the API directly. That’s what &lt;code&gt;bunny api&lt;/code&gt; is for.&lt;/p&gt;

&lt;p&gt;It’s a raw, authenticated HTTP client for the entire bunny.net API. Pick a method, pass a path, and go:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="err"&gt;#&lt;/span&gt; &lt;span class="nx"&gt;List&lt;/span&gt; &lt;span class="nx"&gt;your&lt;/span&gt; &lt;span class="nx"&gt;pull&lt;/span&gt; &lt;span class="nx"&gt;zones&lt;/span&gt;
&lt;span class="nx"&gt;bunny&lt;/span&gt; &lt;span class="nx"&gt;api&lt;/span&gt; &lt;span class="nx"&gt;GET&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nx"&gt;pullzone&lt;/span&gt;

&lt;span class="err"&gt;#&lt;/span&gt; &lt;span class="nx"&gt;Grab&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="nx"&gt;specific&lt;/span&gt; &lt;span class="nx"&gt;DNS&lt;/span&gt; &lt;span class="nx"&gt;zone&lt;/span&gt;
&lt;span class="nx"&gt;bunny&lt;/span&gt; &lt;span class="nx"&gt;api&lt;/span&gt; &lt;span class="nx"&gt;GET&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nx"&gt;dnszone&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mi"&gt;12345&lt;/span&gt;

&lt;span class="err"&gt;#&lt;/span&gt; &lt;span class="nx"&gt;Create&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="nx"&gt;resource&lt;/span&gt; &lt;span class="kd"&gt;with&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt; &lt;span class="nx"&gt;body&lt;/span&gt;
&lt;span class="nx"&gt;bunny&lt;/span&gt; &lt;span class="nx"&gt;api&lt;/span&gt; &lt;span class="nx"&gt;POST&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nx"&gt;videolibrary&lt;/span&gt; &lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;{"Name":"uploads","ReplicationRegions":["DE","NY"]}&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every request is automatically authenticated with your current profile, and every response is pretty-printed JSON by default. Pair it with &lt;code&gt;--output json&lt;/code&gt; and &lt;code&gt;jq&lt;/code&gt; to build quick one-liners:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="nx"&gt;bunny&lt;/span&gt; &lt;span class="nx"&gt;api&lt;/span&gt; &lt;span class="nx"&gt;GET&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nx"&gt;pullzone&lt;/span&gt; &lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="nx"&gt;output&lt;/span&gt; &lt;span class="nx"&gt;json&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;jq&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;.[].Name&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also pipe request bodies from stdin, which makes it easy to compose with other tools or feed in generated payloads:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="nx"&gt;cat&lt;/span&gt; &lt;span class="nx"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;json&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;bunny&lt;/span&gt; &lt;span class="nx"&gt;api&lt;/span&gt; &lt;span class="nx"&gt;POST&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nx"&gt;dnszone&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Think of &lt;code&gt;bunny api&lt;/code&gt; as the escape hatch. If the bunny.net API supports it, you can call it from your terminal right now — no wrapper command needed, no dashboard required. It’s especially useful for AI agents that need to access endpoints beyond the built-in commands.&lt;/p&gt;

&lt;h2&gt;
  
  
  Built like the CLIs you already trust
&lt;/h2&gt;

&lt;p&gt;We followed the &lt;a href="https://clig.dev/" rel="noopener noreferrer"&gt;Command Line Interface Guidelines&lt;/a&gt; closely. The conventions that make &lt;code&gt;git&lt;/code&gt;, &lt;code&gt;docker&lt;/code&gt;, and &lt;code&gt;kubectl&lt;/code&gt; feel predictable - we wanted &lt;code&gt;bunny&lt;/code&gt; to feel that way from the start.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Interactive or scriptable - your call.&lt;/strong&gt; Prompts and spinners are TTY-aware. They show up in your terminal but stay out of the way in CI or when piping output.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Structured output everywhere.&lt;/strong&gt; Every command supports &lt;code&gt;--output json&lt;/code&gt;. Primary output goes to stdout, messages go to stderr, so piping always works cleanly:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;bunny db list &lt;span class="nt"&gt;--output&lt;/span&gt; json | jq &lt;span class="s1"&gt;'.[].name'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Clear, helpful errors.&lt;/strong&gt; Errors are written in plain language with hints on how to fix them. Exit codes are meaningful: &lt;code&gt;1&lt;/code&gt; for fixable problems, &lt;code&gt;2&lt;/code&gt; for internal errors. With &lt;code&gt;--output json&lt;/code&gt;, errors come back as structured JSON too.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Respects your environment.&lt;/strong&gt; The CLI honors &lt;code&gt;NO_COLOR&lt;/code&gt;, supports named profiles for switching between accounts, and reads &lt;code&gt;BUNNYNET_API_KEY&lt;/code&gt; from your environment when you'd rather skip interactive login:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;bunny config profile create &lt;span class="nt"&gt;--name&lt;/span&gt; work
bunny login &lt;span class="nt"&gt;--profile&lt;/span&gt; work
bunny db list &lt;span class="nt"&gt;--profile&lt;/span&gt; work
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Your AI agent already knows how to use it
&lt;/h2&gt;

&lt;p&gt;There's a growing question in the developer tools space: do AI agents need custom protocols, or are the CLI tools developers already use enough?&lt;/p&gt;

&lt;p&gt;Increasingly, the answer is that CLIs win.&lt;/p&gt;

&lt;p&gt;AI models have been trained on billions of lines of terminal interactions. When an agent reaches for a CLI, it's drawing on deeply learned patterns, not adapting to a bespoke integration. Every bunny CLI command that returns structured JSON is a command an AI agent can already use, with zero extra setup.&lt;/p&gt;

&lt;p&gt;If you're working with Claude Code, Cursor, or Windsurf, your assistant can already create databases, manage tokens, and query data through the bunny CLI,  the same way it uses &lt;code&gt;git&lt;/code&gt; or &lt;code&gt;npm&lt;/code&gt; today. No MCP server to configure. No schema tokens eating your context window. The CLI you use is the same interface your agent uses.&lt;/p&gt;

&lt;p&gt;The CLI comes with agent skills for databases and scripts so your agent knows how to get started. Below we can see Claude Code discovered the tool, skills, and created a database and schema for a new project.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F6fokvlbk9q50cny05a3s.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F6fokvlbk9q50cny05a3s.png" alt=" " width="800" height="920"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What's coming next
&lt;/h2&gt;

&lt;p&gt;Database support is the starting point. Here's where we're headed.&lt;/p&gt;

&lt;h3&gt;
  
  
  Edge Scripting
&lt;/h3&gt;

&lt;p&gt;Scaffold a project, deploy serverless functions to the edge, and manage secrets, all from the terminal. Deployment history and rollbacks are on the roadmap too.&lt;/p&gt;

&lt;h3&gt;
  
  
  Storage
&lt;/h3&gt;

&lt;p&gt;Create buckets, list and sync files, and manage access to S3-compatible storage. The same operations you'd do in the dashboard or with a third-party client, built directly into the CLI with your existing auth.&lt;/p&gt;

&lt;h3&gt;
  
  
  Magic Containers Apps
&lt;/h3&gt;

&lt;p&gt;If you've ever wanted to go from a &lt;code&gt;Dockerfile&lt;/code&gt; to a running, globally distributed application in a single command, that's what we’re adding next.&lt;/p&gt;

&lt;h3&gt;
  
  
  The bigger picture
&lt;/h3&gt;

&lt;p&gt;Our goal is a workflow where you go from an empty directory to a fully deployed application without leaving the terminal. Database provisioned, edge functions live, storage configured, containers scaled. Whether you're typing the commands or your AI assistant is running them, it's the same tool, the same output, the same interface.&lt;/p&gt;

&lt;p&gt;Every bunny.net product, one CLI.&lt;/p&gt;

&lt;h2&gt;
  
  
  Built in the open, built in TypeScript
&lt;/h2&gt;

&lt;p&gt;The bunny CLI is open source, and we’re developing it in public. This isn’t a finished product we’re handing to developers. It’s an active project we want to build with you. &lt;/p&gt;

&lt;p&gt;The bunny.net developer platform is JavaScript-native. Edge Scripts run with Deno and Node.js compatibility. The developers building on bunny.net write JavaScript and TypeScript. By keeping the CLI in the same language, we can share code between the CLI and the scripts developers write. Use exports, generated clients, and utilities written for the CLI inside Edge Scripts. &lt;/p&gt;

&lt;p&gt;One language for the CLI, the API client, the config schemas, and the edge runtime means fewer switches and a codebase that any JS developer can read, debug, or contribute to. &lt;/p&gt;

&lt;p&gt;If something is broken, &lt;a href="https://github.com/BunnyWay/cli/issues" rel="noopener noreferrer"&gt;open an issue&lt;/a&gt;. If you want a feature, tell us. If you want to contribute, pull requests are welcome. The CLI is built with TypeScript, Yargs, and a lot of packages that should feel very familiar.&lt;/p&gt;

&lt;h2&gt;
  
  
  Get started
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-g&lt;/span&gt; @bunny.net/cli
bunny login
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://github.com/bunnyWay/cli" rel="noopener noreferrer"&gt;Star the repo on GitHub&lt;/a&gt;, join us on &lt;a href="https://discord.com/invite/bunnynet" rel="noopener noreferrer"&gt;Discord&lt;/a&gt;, and let’s build this together.&lt;/p&gt;

</description>
      <category>cli</category>
      <category>devtools</category>
      <category>database</category>
      <category>devops</category>
    </item>
    <item>
      <title>Build your own caching rules with pre-cache execution and Cache API in Bunny Edge Scripting</title>
      <dc:creator>Marek Nalikowski</dc:creator>
      <pubDate>Tue, 03 Nov 2026 15:13:10 +0000</pubDate>
      <link>https://dev.to/bunnydotnet/build-your-own-caching-rules-with-pre-cache-execution-and-cache-api-in-bunny-edge-scripting-3k5d</link>
      <guid>https://dev.to/bunnydotnet/build-your-own-caching-rules-with-pre-cache-execution-and-cache-api-in-bunny-edge-scripting-3k5d</guid>
      <description>&lt;p&gt;&lt;em&gt;Originally published at bunny.net on July 28, 2026.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Until now, &lt;a href="https://docs.bunny.net/scripting" rel="noopener noreferrer"&gt;Bunny Edge Scripting&lt;/a&gt; has had an opinionated default: your code runs after the CDN cache. That's great for efficiency because fully cached traffic never executes your script. But it also means that the moment a response gets cached, your code is out of the loop.&lt;/p&gt;

&lt;p&gt;Today, that's becoming a choice instead of a rule. Edge Scripting can now also run before the cache, giving your code control over every single request. And with the new Cache API, your scripts can read, write, and delete entries in a separate cache at the edge.&lt;/p&gt;

&lt;p&gt;Let's hop into the details.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why run before the cache
&lt;/h2&gt;

&lt;p&gt;Running after the cache is a feature, not a bug. When a response is cached, the CDN serves it directly and your script never runs. Cached traffic adds zero script execution, which keeps costs low and latency predictable. For delivery-heavy workloads, that's exactly the behavior you want.&lt;/p&gt;

&lt;p&gt;The tradeoff shows up when your workload is dynamic. As soon as a response is cached, you lose per-request control. No auth checks, no personalization, no routing logic; nothing runs until the cache entry expires. The usual workaround is to disable caching for dynamic routes, which solves the problem by throwing away the benefit.&lt;/p&gt;

&lt;p&gt;That means you've had to choose between caching and control. Now you can have both.&lt;/p&gt;

&lt;h2&gt;
  
  
  How pre-cache execution works
&lt;/h2&gt;

&lt;p&gt;Edge Scripts get two new hooks that run on the client side of the cache:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;onClientRequest&lt;/code&gt; fires on every incoming request, before the cache lookup. You can modify the request or return a response directly and short-circuit everything behind it.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;onClientResponse&lt;/code&gt; fires just before a cache or origin response is sent back to the client. If &lt;code&gt;onClientRequest&lt;/code&gt; returns a response directly, the request is short-circuited there.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Together with the existing &lt;code&gt;onOriginRequest&lt;/code&gt; and &lt;code&gt;onOriginResponse&lt;/code&gt; hooks, the request lifecycle now looks like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fe7pcwpq7rp7m8q2kyej8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fe7pcwpq7rp7m8q2kyej8.png" alt="Cache lifecycle showing client hooks, the CDN cache, origin hooks, and the separate script cache" width="800" height="439"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Your code runs on the client side of the cache (&lt;code&gt;onClientRequest&lt;/code&gt;, &lt;code&gt;onClientResponse&lt;/code&gt;) and on the origin side (&lt;code&gt;onOriginRequest&lt;/code&gt;, &lt;code&gt;onOriginResponse&lt;/code&gt;). The CDN cache is served automatically, while your script can also read and write a separate, script-controlled cache.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;On a hit, the CDN cache answers and your client-side hooks run around it. On a miss, the request continues to the origin hooks and back, writing to the cache on the way if it's cacheable. Either way, your code sits before the cache lookup and just before the response goes out, so you get control around the cache without bypassing it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Meet the Cache API
&lt;/h2&gt;

&lt;p&gt;Running before the cache is one half of the story. The other half is a cache your script controls directly, separate from the CDN cache that serves requests automatically.&lt;/p&gt;

&lt;p&gt;That's where the Cache API comes in. Modeled after the browser's &lt;code&gt;Cache&lt;/code&gt; interface, it lets scripts match, put, and delete request/response pairs. Entry lifetimes follow the &lt;code&gt;Cache-Control&lt;/code&gt; headers you set on the responses you write, and expired entries are purged automatically.&lt;/p&gt;

&lt;p&gt;Here's a pattern for taking ownership of a cache entry's lifecycle: serve a cached value on &lt;code&gt;GET&lt;/code&gt;, refresh it on &lt;code&gt;POST&lt;/code&gt;, and purge the exact entry on &lt;code&gt;DELETE&lt;/code&gt;. The key detail is that all three handlers build the same URL-based key, so reads, writes, and deletes all target the same entry.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="kd"&gt;as &lt;/span&gt;&lt;span class="nx"&gt;BunnySDK&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@bunny.net/edgescript-sdk&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// GET serves the cached entry, POST refreshes it, DELETE purges it.&lt;/span&gt;
&lt;span class="c1"&gt;// (Error handling omitted: match, put, and delete can all throw.)&lt;/span&gt;
&lt;span class="nx"&gt;BunnySDK&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;net&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;http&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;serve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;request&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Request&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Response&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;cache&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;caches&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;demo:v1&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;key&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;URL&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// one key for all three&lt;/span&gt;

  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;method&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;POST&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;fresh&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;Response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;refreshedAt&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;toISOString&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Cache-Control&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;max-age=60&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;cache&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;put&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;fresh&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;clone&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Response&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Refreshed.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Cache-Control&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;no-cache&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;method&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;DELETE&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;deleted&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;cache&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;delete&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Response&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;deleted&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Purged.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Nothing to purge.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Cache-Control&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;no-cache&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;cached&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;cache&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;match&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;cached&lt;/span&gt; &lt;span class="o"&gt;??&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Response&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;No cached value yet.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;404&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Cache-Control&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;no-cache&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That same pattern scales up to tenant-aware keys, microcaching, manual refresh hooks, and exact-entry purges. It's a script-controlled cache at the edge, separate from the automatic CDN cache: you decide how entries are created, found, and removed.&lt;/p&gt;

&lt;p&gt;A few things to know before you design around it:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Cache contents are regional.&lt;/strong&gt; Entries live in the region where they were created and don't replicate globally. A page cached in Frankfurt gets cached again in Singapore on the first request there.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cache keys are yours to design.&lt;/strong&gt; An entry's key is exactly the URL or Request you pass, nothing more. There's no automatic normalization, so &lt;code&gt;/page&lt;/code&gt; and &lt;code&gt;/page?utm_source=x&lt;/code&gt; are two different entries unless your code makes them one. We recommend building keys from the current request URL. That discipline pays off when it's time to delete an entry: you can only purge it if you can rebuild its exact key.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Pull Zone domains share cache instances.&lt;/strong&gt; Cache instances are shared across all domains associated with your Pull Zone, but they need to be accessed through the incoming request's hostname. For multi-domain Pull Zones, build keys from the current request host or request URL.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Limits:&lt;/strong&gt; &lt;code&gt;match&lt;/code&gt;, &lt;code&gt;put&lt;/code&gt;, and &lt;code&gt;delete&lt;/code&gt; are the supported operations on Cache instances, with a 100 MB limit per cache file.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Pre-cache execution and the Cache API are two separate features, but they're better together. Running before the cache gives you control on every request, and the Cache API is how you put caching back in on your terms.&lt;/p&gt;

&lt;p&gt;This unlocks two major use cases:&lt;/p&gt;

&lt;h2&gt;
  
  
  Multi-tenant delivery on your caching rules
&lt;/h2&gt;

&lt;p&gt;When every hostname, path, or account maps to a different tenant, one-size-fits-all cache rules stop being enough. With scripts in front of the cache, your delivery logic can:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Key cache entries per tenant&lt;/strong&gt;, using tenant-aware prefixes inside versioned named caches, with TTLs controlled by the &lt;code&gt;Cache-Control&lt;/code&gt; headers on the responses you write.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Invalidate exact entries surgically&lt;/strong&gt;, as long as your application can reconstruct the keys it wrote. This is exact-key deletion, not wildcard purge or tenant-wide key listing.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Decorate cache or origin responses per tenant&lt;/strong&gt; in &lt;code&gt;onClientResponse&lt;/code&gt;, adding headers or security policies without waking up the origin.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Build dynamic caching patterns&lt;/strong&gt; the CDN doesn't offer out of the box, like microcaching rendered pages or using explicit &lt;code&gt;POST&lt;/code&gt; / &lt;code&gt;DELETE&lt;/code&gt; handlers to refresh and purge known cache entries.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you run a platform where your customers' content flows through your zones, this lets you turn edge caching from a fixed behavior into part of your product logic.&lt;/p&gt;

&lt;h2&gt;
  
  
  Serverless CRUD apps at the edge
&lt;/h2&gt;

&lt;p&gt;Until now, a dynamic multi-user app didn't really fit the after-cache model. Sessions, per-user responses, and cache decisions all need code on every request, so you'd end up disabling caching and losing the main benefit of running at the edge.&lt;/p&gt;

&lt;p&gt;With pre-cache execution, the pieces fall into place:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Auth and sessions&lt;/strong&gt; run in &lt;code&gt;onClientRequest&lt;/code&gt;, on every request.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;You decide what's cacheable&lt;/strong&gt;, using the Cache API to cache rendered pages or API responses for seconds or minutes, and serving everything else dynamically.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Compute stays request-based&lt;/strong&gt;, so a side project that gets no traffic costs nothing in compute, and a production app scales with traffic.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Pair Edge Scripting with &lt;a href="https://bunny.net/blog/meet-bunny-database-the-sql-service-that-just-works/" rel="noopener noreferrer"&gt;Bunny Database&lt;/a&gt; for state&lt;/strong&gt;, so you can build full-stack serverless apps, with read replication to serve reads close to your users.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And since both Edge Scripting and Bunny Database are supported by the &lt;a href="https://docs.bunny.net/cli" rel="noopener noreferrer"&gt;bunny.net CLI&lt;/a&gt;, you (and your agent) can go from local to prod without leaving the terminal.&lt;/p&gt;

&lt;h2&gt;
  
  
  You choose where your code runs
&lt;/h2&gt;

&lt;p&gt;Post-cache execution stays the default, and it's still the most cost-effective way to run delivery logic: when cached traffic doesn't need script logic, the CDN can serve it directly without invoking your code.&lt;/p&gt;

&lt;p&gt;Pre-cache execution is the opt-in mode for the routes and Pull Zones where you need per-request control.&lt;/p&gt;

&lt;p&gt;Other platforms typically put compute in front of the cache by default, so even cache hits can pass through your code path. With bunny.net you can now choose to keep compute out of the hot path when the cache is enough, or move it in front of the cache when your application needs control.&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting started
&lt;/h2&gt;

&lt;p&gt;Both pre-cache execution and the Cache API are now available in &lt;a href="https://docs.bunny.net/product-release-stages" rel="noopener noreferrer"&gt;public preview&lt;/a&gt;. The Cache API works in any Edge Script today. There's nothing to enable. Pre-cache execution is a toggle in the dashboard:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Middleware scripts:&lt;/strong&gt; in your Pull Zone, under &lt;strong&gt;General → Origin → Run script before cache&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Standalone scripts:&lt;/strong&gt; the same toggle in the Pull Zone, or enable it directly in the script's settings.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For more details, check out the docs:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://docs.bunny.net/scripting/before-cache" rel="noopener noreferrer"&gt;Pre-cache execution&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.bunny.net/scripting/cache-api" rel="noopener noreferrer"&gt;Cache API reference&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Happy building and let us know what you think on &lt;a href="https://discord.com/invite/bunnynet" rel="noopener noreferrer"&gt;Discord&lt;/a&gt;!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>devops</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
