Command-Line Interface
JsWeb comes with a powerful command-line interface (CLI) that helps you manage your application. You can use it to create new projects, run the development server, manage database migrations, and more.
Table of Contents
Available Commands
Here's a quick overview of all CLI commands:
| Command | Purpose |
|---|---|
jsweb run |
Start the development server |
jsweb new |
Create a new JsWeb project |
jsweb db prepare |
Generate a new migration |
jsweb db upgrade |
Apply migrations to database |
jsweb db downgrade |
Revert the last migration |
jsweb create-admin |
Create a new admin user |
jsweb run
Starts the development server with optional configuration.
Options
| Option | Description | Default |
|---|---|---|
--host |
The host to bind to | 127.0.0.1 |
--port |
The port to listen on | 8000 |
--reload |
Enable auto-reloading on code changes | Disabled |
--qr |
Display QR code for network access | Disabled |
Examples
# Basic server
jsweb run
# With auto-reload (recommended for development)
jsweb run --reload
# On different port
jsweb run --port 5000
# Accessible from other machines
jsweb run --host 0.0.0.0 --reload
# With QR code for mobile access
jsweb run --reload --qr
# All options combined
jsweb run --host 0.0.0.0 --port 3000 --reload --qr
Development
Always use --reload during development to automatically restart the server when you save changes.
Production
The development server is NOT suitable for production. Use a proper ASGI server like: - Uvicorn - Hypercorn - Daphne
jsweb new
Creates a new JsWeb project with a production-ready directory structure.
What Gets Created
my_project/
├── alembic/ # Database migrations
│ ├── versions/
│ └── env.py
├── static/ # Static files (CSS, JS, images)
│ └── global.css
├── templates/ # HTML templates
│ ├── login.html
│ ├── profile.html
│ ├── register.html
│ └── starter_template.html
├── alembic.ini # Alembic configuration
├── app.py # Main application
├── auth.py # Authentication
├── config.py # Configuration
├── forms.py # Form definitions
├── models.py # Database models
└── views.py # Route handlers
Quick Start After Creating
jsweb db
Database management commands for migrations using Alembic.
jsweb db prepare
Generate a new migration based on model changes.
Options:
| Option | Description | Required |
|---|---|---|
-m, --message |
Description of the migration | Yes |
Examples:
# Simple migration
jsweb db prepare -m "Add email field to users"
# Detailed messages are helpful
jsweb db prepare -m "Create products table with inventory tracking"
# Structural changes
jsweb db prepare -m "Add foreign key relationships between posts and users"
Descriptive Messages
Use clear, descriptive messages that explain what the migration does. This helps when reviewing migration history.
jsweb db upgrade
Apply all pending migrations to the database.
When to use:
- After creating a new project (to initialize database)
- After pulling code with new migrations
- Before deploying to production
Examples:
# Apply all pending migrations
jsweb db upgrade
# Deploy workflow
git pull
jsweb db upgrade
jsweb run --reload
Backup Before Upgrade
Always backup your database before running migrations in production!
jsweb db downgrade
Revert the last applied migration (one step back).
Use cases:
- Accidentally applied the wrong migration
- Need to test migration rollback
- Rolling back changes
Examples:
# Revert last migration
jsweb db downgrade
# Check status after downgrade
jsweb db upgrade # See current migrations
Production Downgrades
Be very careful downgrading in production. Data loss may occur depending on the migration.
jsweb create-admin
Create a new administrator user for the admin interface.
Interactive Prompts
The command will ask for: 1. Username: Unique admin username 2. Email: Admin email address 3. Password: Secure password (input hidden)
$ jsweb create-admin
Username: admin
Email: admin@example.com
Password: ••••••••
Password (confirm): ••••••••
Admin user 'admin' created successfully!
Multiple Admins
You can create multiple admin users by running this command multiple times.
Strong Passwords
Always use strong, unique passwords for admin accounts. Consider using a password manager.
Tips & Tricks
Command Shortcuts
Create shell aliases for common commands:
Working with Migrations
Good migration workflow:
Environment Variables
Configure server via environment variables:
Port Already in Use
If port 8000 is already in use: