Using the CLI
How to start a bknd instance using the CLI.
The bknd package includes a command-line interface (CLI) that allows you to run a bknd instance and perform various tasks.
Here is the output:
Starting an instance (run
)
To see all available run
options, execute npx bknd run --help
.
To order in which the connection is determined is as follows:
--db-url
--config
or reading the filesystem looking forbknd.config.[js|ts|mjs|cjs|json]
--memory
- Environment variables
DB_URL
andDB_TOKEN
in.env
or.dev.vars
- Fallback to file-based database
data.db
File-based database
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.
Using configuration file (bknd.config.*
)
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:
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:
If you still want to use a .ts
extension, you can start the CLI e.g. using node
(>=v22.6.0):
Or with tsx
:
Turso/LibSQL database
To start an instance with a Turso/LibSQL database, run the following:
The --db-token
option is optional and only required if the database is protected.
In-memory database
To start an instance with an ephemeral in-memory database, run the following:
Keep in mind that the database is not persisted and will be lost when the process is terminated.