Getting Started
Run db-studio with npx, connect it through DATABASE_URL in your .env file or --database-url, and use the CLI options for ports, env files, and package scripts.
Quick Start
No installation needed! Just run this command:
npx db-studioThis runs the latest version of db-studio using your current folder as the project location.
How It Works
db-studio looks for your database connection in this order:
- Checks for a
.envfile in your current folder - If not found, searches parent folders until it finds one
- Reads
DATABASE_URLfrom that file - If
DATABASE_URLisn't in the file, checks your system environment variables - If there is still no URL, the app opens on the Connect page, where you paste one
Saved connections
Every connection that opens, from the CLI or the Connect page, is saved to
~/.dbstudio/connections.json. The file holds passwords, so only your user can read it, and
the browser only ever sees URLs with the password hidden. Switch connections from the
connection name in the sidebar footer, or open All connections… to rename, color or
delete them.
The server listens on 127.0.0.1 only. To reach it from another machine, set HOST=0.0.0.0 and list the hostname or IP you connect through in ALLOWED_HOSTS, for example ALLOWED_HOSTS=db.lan,10.0.0.5. Use comma-separated hostnames without ports; put IPv6 addresses in brackets. Localhost access needs no override. When HOST is not loopback (127.0.0.1, localhost or ::1), the browser asks for a password: use any username and the password printed at startup, or set your own with DB_STUDIO_PASSWORD.
Setting Up Your Database Connection
Create a .env file in your project:
# .env
DATABASE_URL=postgresql://user:password@localhost:5432/mydatabaseThen run:
npx db-studiodb-studio will:
- Find and read your
.envfile - Start a server on port
3333 - Print the address,
http://localhost:3333, for you to open in your browser
Add --open to open it in your browser automatically.
Command Options
You can customize how db-studio runs with these options:
| Option | What It Does | Example |
|---|---|---|
-e, --env <path> | Use a specific .env file | npx db-studio --env .env.local |
-n, --var-name <name> | Use a different variable name instead of DATABASE_URL | npx db-studio --var-name MY_DB_URL |
-p, --port <number> | Change the server port (default is 3333) | npx db-studio --port 4000 |
-d, --database-url <url> | Provide connection string directly without .env file | npx db-studio -d "postgresql://user:pass@localhost:5432/mydb" |
--open | Open db-studio in your browser once it starts | npx db-studio --open |
--no-open | Do not open the browser (the default) | npx db-studio --no-open |
-s, --status | Only check if connection works (doesn't open the UI) | npx db-studio --status |
-v, --version | Show the installed version | npx db-studio --version |
-h, --help | Show all available options | npx db-studio --help |
Real Examples
# Use a different env file for local development
npx db-studio --env .env.local
# Use production env file with custom port
npx db-studio --env .env.production --port 4444
# Connect directly without env file (good for quick tests)
npx db-studio --database-url "postgresql://user:pass@host:5432/prod"
# Use custom variable name with specific env file
npx db-studio --env .env.staging --var-name STAGING_DB_URL
# Just check if your connection works
npx db-studio --statusAdd to Your Project
You can add db-studio to your package.json scripts:
{
"scripts": {
"db:studio": "npx db-studio"
}
}Then run it with:
npm run db:studioPassing Options Through npm/bun
When using npm run or bun run, add -- before your options:
# Local dev with custom env file
npm run db:studio -- --env .env.local
# Production with custom port
bun run db:studio -- --env .env.production --port 4444
# Custom variable name
npm run db:studio -- --var-name STAGING_DB_URLSwitching from Other Tools
From Prisma Studio
Update your scripts:
"scripts": {
- "studio": "npx prisma studio"
+ "db:studio": "npx db-studio"
}db-studio uses the same DATABASE_URL from your .env file. No extra config needed!
From Drizzle Studio
Update your scripts:
"scripts": {
- "db:studio": "npx drizzle-kit studio"
+ "db:studio": "npx db-studio"
}Works the same way - just uses your existing DATABASE_URL.