create-cloud-db
v1.0.5
Published
CLI to create a Turso database and write TURSO_* env vars to .env file
Readme
create-cloud-db
create-cloud-db is a small CLI that creates a Turso database and manages the TURSO_DATABASE_URL and TURSO_AUTH_TOKEN values in your local .env file.
It is designed for quick local setup so you can be ready to connect from Node, frameworks, or serverless environments with minimal manual configuration.
Installation
You must first login to turso with:
bun i -g turso
turso auth login
# or
bun x turso auth loginThen run:
# will ask for name
npm create cloud-db
# or
npx create-cloud-db
# or
npx create-cloud-db [myapp-db]
Or install globally:
npm install -g create-cloud-db
create-cloud-db myapp-dbWhat it does
When you run the command, the CLI:
- Ensures you are logged into Turso via
turso auth login. - Creates a Turso database if it does not already exist.
- Generates a database URL and an auth token via the Turso CLI.
- Overwrites (not appends) the
TURSO_DATABASE_URLandTURSO_AUTH_TOKENentries in your local.envfile.
After running, your .env file will contain something like:
TURSO_DATABASE_URL=libsql://your-db-name.region.turso.io
TURSO_AUTH_TOKEN=eyJhbGciOiJFZERTQSIsInR5cCI6IkpXVCJ9...Add to package.json
"db:create": "create-cloud-db",
"db:generate": "drizzle-kit generate",
"db:push": "drizzle-kit push",
"db:studio": "drizzle-kit studio",Environment file behavior
- The CLI reads your existing
.envfile if present. - It updates or inserts
TURSO_DATABASE_URLandTURSO_AUTH_TOKENkeys. - The
.envfile is rewritten, so old placeholder values are removed and replaced with valid values.
Example with Drizzle
// drizzle.config.ts
import { defineConfig } from 'drizzle-kit';
export default defineConfig({
dialect: 'turso',
schema: './src/lib/db/schema.ts',
out: './drizzle',
dbCredentials: {
url: process.env.TURSO_DATABASE_URL || 'file:./localdb.sqlite',
authToken: process.env.TURSO_AUTH_TOKEN,
},
});📝 License
MIT License - Star this repo so it can grow features! 🌟
