BaasixBaasix
Getting Started

Quick Start

Get a Baasix backend running in under 5 minutes. This guide covers the essentials to make your first API call.

Prerequisites

Before you begin, ensure you have:

  • Node.js v18 or later
  • PostgreSQL v14 or later
  • npm or yarn

1. Create a New Project

# Create project directory
mkdir my-baasix-app
cd my-baasix-app
npm init -y

# Install Baasix
npm install @baasix/baasix

2. Create Entry Point

Create a server.js file:

import { startServer } from '@baasix/baasix';

startServer().catch((error) => {
  console.error('Failed to start server:', error);
  process.exit(1);
});

Update package.json to use ES modules:

{
  "type": "module",
  "scripts": {
    "dev": "node server.js"
  }
}

3. Configure Environment

Create a .env file with your database connection:

# Database (required)
DATABASE_URL="postgresql://postgres:postgres@localhost:5432/baasix"

# Security (required - minimum 32 characters)
SECRET_KEY=your-secret-key-at-least-32-characters

# Server
PORT=8056

4. Start the Server

npm run dev

Your Baasix server is now running at http://localhost:8056.

5. Create Your First User

Register an admin user:

curl -X POST http://localhost:8056/auth/register \
  -H "Content-Type: application/json" \
  -d '{
    "firstName": "Admin",
    "lastName": "User",
    "email": "admin@example.com",
    "password": "password123"
  }'

Save the token from the response for authenticated requests.

6. Create a Schema

Create your first data model:

curl -X POST http://localhost:8056/schemas \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -d '{
    "collectionName": "posts",
    "schema": {
      "name": "Post",
      "timestamps": true,
      "fields": {
        "id": {
          "type": "UUID",
          "primaryKey": true,
          "defaultValue": { "type": "UUIDV4" }
        },
        "title": {
          "type": "String",
          "allowNull": false
        },
        "content": {
          "type": "Text"
        },
        "published": {
          "type": "Boolean",
          "defaultValue": false
        }
      }
    }
  }'

7. Create and Query Items

Create an item:

curl -X POST http://localhost:8056/items/posts \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -d '{
    "title": "Hello Baasix",
    "content": "My first post!",
    "published": true
  }'

Query items:

curl "http://localhost:8056/items/posts?filter={\"published\":{\"eq\":true}}" \
  -H "Authorization: Bearer YOUR_TOKEN"

Next Steps

You now have a working Baasix backend. Explore further:

Using the CLI (Alternative)

For a faster setup with templates and configuration prompts, use the Baasix CLI:

# Install CLI globally
npm install -g baasix

# Create a new project interactively
npx baasix init

# Or with options
npx baasix init --name my-api --template api

The CLI creates a fully configured project with environment files, extensions folder, and deployment scripts.

On this page