Appwrite for Web
Published: 2021-10-26 17:46:52

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

```bash
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
``` 

####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
```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
```
######POWERSHELL
```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
```
 
####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:

```bash
docker-compose up -d --remove-orphans
```

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)](https://npmjs.com/) from your command line to add Appwrite SDK to your project.
```bash
npm install appwrite
```
If you're using a bundler (like [Browserify](http://browserify.org/) or [webpack](https://webpack.js.org/)), you can import the Appwrite module when you need it:
```
import { Appwrite } from "appwrite";
```
####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: 
```html
<script src="https://cdn.jsdelivr.net/npm/appwrite@4.0.4"></script>
```

###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
;

```
###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);
        });

```

###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](https://appwrite.io/docs/realtime).
```
// 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);
    }
});

```

###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);
    }
});

```

###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](https://github.com/appwrite/todo-with-react)
[Live Example](https://appwrite-todo-with-react.vercel.app/)

#####Todo App with Vue JS 
[Github repo](https://github.com/appwrite/todo-with-vue)
[Live Example](https://appwrite-todo-with-vue.vercel.app/) 

#####Todo App with Angular 
[Github repo](https://github.com/appwrite/todo-with-angular)
[Live Example](https://appwrite-todo-with-angular.vercel.app/)

#####Todo App with Svelte 
[Github repo](https://github.com/appwrite/todo-with-svelte)
[Live Example](https://appwrite-todo-with-svelte.vercel.app/)

###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.