How to Get Started with Appwrite as Your Backend Solution

Appwrite is an open-source backend-as-a-service platform that simplifies building modern applications. It provides ready-made APIs for authentication, databases, storage, and functions—saving you from writing repetitive server code. In this tutorial, you’ll learn how to set up Appwrite and use its core features to power your app.

Begin by signing up at Appwrite’s cloud console or deploying a self-hosted instance using Docker. Once your project is created, note the Project ID and API Endpoint—you’ll need them for SDK setup. Install the Appwrite client SDK via npm or your preferred package manager: npm install appwrite.

Article illustration

1. Setting Up Authentication

Appwrite offers email/password, OAuth (Google, GitHub, etc.), and anonymous login. Initialize the client in your app:

import { Client, Account } from 'appwrite';

const client = new Client()
    .setEndpoint('https://[YOUR_ENDPOINT]') // Your Appwrite endpoint
    .setProject('[PROJECT_ID]');            // Your project ID

const account = new Account(client);

// Register a new user
const user = await account.create(
    'user@example.com', 'password123', 'John Doe'
);

Use account.createEmailSession() to log in and account.get() to verify the current session. Store the session token on the client for persistence.

2. Working with Databases

Appwrite’s database lets you create collections (similar to tables) and store documents (JSON). First, define a collection via the Console or using the SDK:

import { Databases } from 'appwrite';

const databases = new Databases(client);

// Create a document
const doc = await databases.createDocument(
    'DATABASE_ID',
    'COLLECTION_ID',
    'unique()', // Auto-generate ID
    { title: 'My Note', content: 'Hello Appwrite!' }
);

Use listDocuments() with filters and pagination for queries. Permissions can be set per document (read/write for specific roles or users).

3. Storing Files in the Bucket

File uploads are straightforward. Create a bucket in the Console, then use the Storage service:

import { Storage } from 'appwrite';

const storage = new Storage(client);

const file = await storage.createFile(
    'BUCKET_ID',
    'unique()',
    document.getElementById('upload').files[0]
);

Retrieve files with getFilePreview() for images or getFileDownload() for raw downloads. Appwrite automatically handles file validation and thumbnails.

4. Running Serverless Functions

Write custom backend logic using Appwrite Functions. Deploy a Node.js or Python script that triggers on HTTP requests, database events, or schedules. Example function that sends a welcome email:

// Function code (Node.js 18)
module.exports = async function (req, res) {
    const { email } = req.body;
    // Send email using your provider
    res.json({ success: true });
};

Functions scale automatically and can access Appwrite services via the SDK with elevated permissions.

Conclusion: Appwrite handles the undifferentiated heavy lifting of backend work. Start with authentication and storage, then add databases and functions as your app grows. Check the official documentation for advanced features like real-time subscriptions and custom domains. Happy coding!

sarah antaboga
Author: sarah antaboga

Leave a Reply

Your email address will not be published. Required fields are marked *