Database and files in your app (env.DB and env.BUCKET)
Updated: 2026-07-18 · YaDominios
Your site on YaDominios Cloud can have a database and file storage. If your repository includes a _worker.js file, we automatically create a database (env.DB) and a file bucket (env.BUCKET); if you include schema.sql, we create your tables. Everything lives in our cloud, with no servers to set up.
How to enable it (for your developer)
A regular site only carries static files. To give it a database and file storage, your repository must include, at the published root:
- _worker.js — your app's server code. It receives requests and uses
env.DB(database) andenv.BUCKET(files). Anything that isn't your code, it serves as a site withenv.ASSETS.fetch(request). - schema.sql (optional) — your database tables; we create them on publish.
- index.html — your page (the frontend).
Minimal _worker.js example
export default {
async fetch(req, env) {
const url = new URL(req.url);
if (url.pathname === "/data") {
const { results } = await env.DB.prepare("SELECT * FROM my_table").all();
return Response.json(results);
}
return env.ASSETS.fetch(req); // serves your site
}
};
⚠️ Don't use the /api/ prefix for your backend routes. On YaDominios Cloud static files are served before your code, and in apps that ship assets (e.g. Next.js/OpenNext) the routing can capture /api/* and return 404 before reaching your worker. Use any other prefix for your endpoints: /data, /media, /upload, etc.
What we give you automatically
- env.DB — your site's own SQL database on YaDominios Cloud (SQLite engine).
- env.BUCKET — your site's own file/image storage on YaDominios Cloud.
- env.UPLOAD_TOKEN — a password the cloud generates on its own to protect your upload route (
/upload). Don't invent it: it's already set, and you can view/copy it in the dashboard. Compare against it in your worker to reject uploads without permission.
You don't have to create anything by hand: when you publish your repo, the database and storage are created automatically and connected to your site. In the dashboard you'll see “Database active” and “Storage active.”
Frequently asked questions
Do I need to install or configure the database?
No. Just include _worker.js in your repo and we create the database and connect it to your site automatically on publish.
How do I create my tables?
Add a schema.sql file to your repository with your CREATE TABLE statements; we run them on publish.
Can I upload my users' images?
Yes. Every app with a backend gets file storage (env.BUCKET) where you keep images and files, with zero egress cost.