DEV Community

Cover image for Appwrite for Web
Rahul Kumar
Rahul Kumar

Posted on • Updated on

Appwrite for Web

Introduction

Appwrite is a development platform providing you with easy yet powerful API and management console to get your next project up and running quickly.
This tutorial will help you start using Appwrite products and build your next project.

Installation

Appwrite is a self-hosted backend server packaged as a set of Docker containers. You can install and run Appwrite on any operating system that can run a Docker CLI. You can use Appwrite on your local desktop or cloud provider of your choice.

System Requirement:

Appwrite was designed to run well on both small and large deployment. The minimum requirements to run Appwrite is as little as 1 CPU core and 2GB of RAM, and an operating system that supports Docker.

Install with Docker:

The easiest way to start running your Appwrite server is by running our Docker installer tool from your terminal. Before running the installation command, make sure you have Docker CLI installed on your host machine.

Unix:

docker run -it --rm \
    --volume /var/run/docker.sock:/var/run/docker.sock \
    --volume "$(pwd)"/appwrite:/usr/src/code/appwrite:rw \
    --entrypoint="install" \
    appwrite/appwrite:0.11.0
Enter fullscreen mode Exit fullscreen mode

Windows:

Hyper-V and Containers Windows features must be enabled to run Appwrite on Windows with Docker. If you don't have these features available, you can install Docker Toolbox that uses Virtualbox to run Appwrite on a Virtual Machine.

CMD
docker run -it --rm ^
    --volume //var/run/docker.sock:/var/run/docker.sock ^
    --volume "%cd%"/appwrite:/usr/src/code/appwrite:rw ^
    --entrypoint="install" ^
    appwrite/appwrite:0.11.0
Enter fullscreen mode Exit fullscreen mode
POWERSHELL
docker run -it --rm ,
    --volume /var/run/docker.sock:/var/run/docker.sock ,
    --volume ${pwd}/appwrite:/usr/src/code/appwrite:rw ,
    --entrypoint="install" ,
    appwrite/appwrite:0.11.0
Enter fullscreen mode Exit fullscreen mode

Manual (using docker-compose.yml):

For advanced Docker users, the manual installation might seem more familiar. To setup Appwrite manually, download the Appwrite base docker-compose.yml and .env files. After the download completes, update the different environment variables as you wish in the .env file and start the Appwrite stack using the following Docker command:

docker-compose up -d --remove-orphans
Enter fullscreen mode Exit fullscreen mode

Once the Docker installation completes, go to your machine hostname or IP address on your browser to access the Appwrite console. Please notice that on non-linux native hosts the server might take a few minutes to start after installation completes.

Create Your First Appwrite Project

Go to your new Appwrite console and once inside, click the icon in the top navigation header or on the 'Create Project' button on your console homepage. Choose a name for your project and click create to get started.

Add Your Web Platform

For you to init your SDK and interact with Appwrite services, you need to add a web platform to your project. To add a new platform, go to your Appwrite console, choose the project you created in the step before and click the 'Add Platform' button.

From the options, choose to add a web platform and add your client app hostname. By adding your hostname to your project platform, you are allowing cross-domain communication between your project and the Appwrite API.

Get Appwrite Web SDK

NPM

Use NPM (node package manager) from your command line to add Appwrite SDK to your project.

npm install appwrite
Enter fullscreen mode Exit fullscreen mode

If you're using a bundler (like Browserify or webpack), you can import the Appwrite module when you need it:

import { Appwrite } from "appwrite";
Enter fullscreen mode Exit fullscreen mode

CDN

To install with a CDN (content delivery network) add the following scripts to the bottom of your tag, but before you use any Appwrite services:

<script src="https://cdn.jsdelivr.net/npm/appwrite@4.0.4"></script>
Enter fullscreen mode Exit fullscreen mode

Init your SDK

Initialize your SDK code with your project ID which can be found in your project settings page.

// Init your Web SDK
const appwrite = new Appwrite();

appwrite
    .setEndpoint('http://localhost/v1') // Your Appwrite Endpoint
    .setProject('455x34dfkj') // Your project ID
;

Enter fullscreen mode Exit fullscreen mode

Make Your First Request

Once your SDK object is set, access any of the Appwrite services and choose any request to send. Full documentation for any service method you would like to use can be found in your SDK documentation or in the API References section.

// Register User
appwrite
    .account.create('me@example.com', 'password', 'Jane Doe')
        .then(response => {
            console.log(response);
        }, error => {
            console.log(error);
        });

Enter fullscreen mode Exit fullscreen mode

Listen to Changes

If you want to listen to changes in realtime from Appwrite, you can subscribe to a variety of channels and receive updates within milliseconds. Full documentation for Realtime can be found here.

// Subscribe to files channel
appwrite.subscribe('files', response => {
    if(response.event === 'storage.files.create') {
        // Log when a new file is uploaded
        console.log(response.payload);
    }
});

Enter fullscreen mode Exit fullscreen mode

Full Example

// Init your Web SDK
const appwrite = new Appwrite();

appwrite
    .setEndpoint('http://localhost/v1') // Your Appwrite Endpoint
    .setProject('455x34dfkj') // Your project ID

// Register User
appwrite
    .account.create('me@example.com', 'password', 'Jane Doe')
        .then(response => {
            console.log(response);
        }, error => {
            console.log(error);
        });

// Subscribe to files channel
appwrite.subscribe('files', response => {
    if(response.event === 'storage.files.create') {
        // Log when a new file is uploaded
        console.log(response.payload);
    }
});

Enter fullscreen mode Exit fullscreen mode

Demos

Below you can find a list of some demos to help you get started with Appwrite for Web using your favorite tools and framework of choice.

Todo App with React JS

Github repo
Live Example

Todo App with Vue JS

Github repo
Live Example

Todo App with Angular

Github repo
Live Example

Todo App with Svelte

Github repo
Live Example

Next Steps

Appwrite has many services and tools to help improve your app and speed up your development. The best way to learn how you can take advantage of them is to explore the different API references docs.

Reference Docs

Discussion (0)