The bknd package includes a command-line interface (CLI) that allows you to run a bknd instance and perform various tasks.
npx bknd
Here is the output:
$ npx bkndUsage: bknd [options] [command]⚡ bknd cli v0.16.0Options: -V, --version output the version number -h, --help display help for commandCommands: user <action> create/update users, or generate a token (auth) types [options] generate types schema [options] get schema run [options] run an instance debug <subject> debug bknd create [options] create a new project copy-assets [options] copy static assets config [options] get default config help [command] display help for command
To see all available run options, execute npx bknd run --help.
$ npx bknd run --helpUsage: bknd run [options]Options: -p, --port <port> port to run on (default: 1337, env: PORT) -m, --memory use in-memory database -c, --config <config> config file --db-url <db> database url, can be any valid libsql url --db-token <db> database token --server <server> server type (choices: "node", "bun", default: "bun") --no-open don't open browser window on start -h, --help display help for command
To order in which the connection is determined is as follows:
--db-url
--config or reading the filesystem looking for bknd.config.[js|ts|mjs|cjs|json]
--memory
Environment variables DB_URL and DB_TOKEN in .env or .dev.vars
By default, a file-based database data.db is used when running without any arguments. You can specify a different file name or path using the --db-url option. The database file will be created in the current working directory if it does not exist.
You can create a configuration file on the working directory that automatically gets picked up: bknd.config.[js|ts|mjs|cjs|json]
Here is an example of a bknd.config.ts file:
import type { BkndConfig } from "bknd/adapter";export default { // you can either specify the connection directly connection: { url: "file:data.db", }, // or use the `app` function which passes the environment variables app: ({ env }) => ({ connection: { url: env.DB_URL, }, }),} satisfies BkndConfig;
The app function is useful if you need a cross-platform way to access the environment variables. For example, on Cloudflare Workers, you can only access environment variables inside a request handler. If you're exclusively using a node-like environment, it's safe to access the environment variables directly from process.env.
If you're using npx bknd run, make sure to create a file in a file format that node can load, otherwise you may run into an error that the file couldn't be found:
[INF] 2025-03-28 18:02:21 Using config from bknd.config.ts[ERR] 2025-03-28 18:02:21 Failed to load config: Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'bknd.config.ts' imported from [...] at packageResolve (node:internal/modules/esm/resolve:857:9) at [...] { code: 'ERR_MODULE_NOT_FOUND'}
If you still want to use a .ts extension, you can start the CLI e.g. using node (>=v22.6.0):
node --experimental-strip-types node_modules/.bin/bknd run