db-studio

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-studio

This 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:

  1. Checks for a .env file in your current folder
  2. If not found, searches parent folders until it finds one
  3. Reads DATABASE_URL from that file
  4. If DATABASE_URL isn't in the file, checks your system environment variables
  5. 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/mydatabase

Then run:

npx db-studio

db-studio will:

  1. Find and read your .env file
  2. Start a server on port 3333
  3. 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:

OptionWhat It DoesExample
-e, --env <path>Use a specific .env filenpx db-studio --env .env.local
-n, --var-name <name>Use a different variable name instead of DATABASE_URLnpx 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 filenpx db-studio -d "postgresql://user:pass@localhost:5432/mydb"
--openOpen db-studio in your browser once it startsnpx db-studio --open
--no-openDo not open the browser (the default)npx db-studio --no-open
-s, --statusOnly check if connection works (doesn't open the UI)npx db-studio --status
-v, --versionShow the installed versionnpx db-studio --version
-h, --helpShow all available optionsnpx 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 --status

Add 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:studio

Passing 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_URL

Switching from Other Tools

From Prisma Studio

Update your scripts:

package.json
 "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:

package.json
 "scripts": {
-  "db:studio": "npx drizzle-kit studio"
+  "db:studio": "npx db-studio"
 }

Works the same way - just uses your existing DATABASE_URL.

On this page