Announcing the Appwrite CLI 🚀
Tags: backend, docker, cli, tutorial
Published: 2021-02-16 14:55:54

---
title: Announcing the Appwrite CLI 🚀
published: true
description: 
tags: backend, docker, cli, tutorial 
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2jhp01nsx9v4vwfbvom1.png
---

Appwrite recently released v0.7, its biggest release yet, and with it comes the much-awaited Appwrite CLI. With the Appwrite CLI you can quickly interact with your Appwrite backend right from your terminal or CI server. The CLI is also cross-platform and offers the same experience on macOS, Windows, and Linux. 

## 🎛 Installation

The Appwrite CLI is a Node based command line tool to help you interact with the Appwrite API. The CLI is distributed both as an [`npm package`](https://www.npmjs.com/package/appwrite-cli) as well as [pre built binaries](https://github.com/christyjacob4/appwrite-node-cli/releases/latest) for specific operating systems and architectures.

### Install using NPM

If you have `npm` installed, it's as easy as running

```sh
$ npm install -g appwrite-cli
```

### Install prebuilt binaries

If you do not have `npm` installed, you can always install the prebuilt binaries for your architecture and OS using our convenient installation scripts.

* Linux / MacOS 
```bash
$ wget -q https://appwrite.io/cli/install.sh  -O - | /bin/bash
```

* Windows
```powershell
$ iwr -useb https://appwrite.io/cli/install.ps1 | iex
```

![Appwrite Install Shield](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/llwaikt1sy8bfbz3pgef.png)
 
Once the installation is complete, you can verify the install using

```sh
$ appwrite -v
```

## 🏁 Getting Started

Before you can use the CLI, you need to login to your Appwrite account. 

```sh
$ appwrite login

? Enter your email test@test.com
? Enter your password ********
✓ Success 
```
This will also prompt you to enter your appwrite endpoint ( default: http://localhost/v1 ) 

### Initialising your project

Once logged in, the CLI needs to be initialised before you can use it with your Appwrite project. You can do this with the `appwrite init project` command. 

```sh
$ appwrite init project
```

The following prompt will guide you through the setup process. The `init` command also creates an `appwrite.json` file representing your Appwrite project.

The `appwrite.json` file does a lot of things. 
* Provides context to the CLI
* Keeps track of all your cloud functions
* Keeps track of all your project's collections
* Helps you deploy your Appwrite project to production and more..

You can also fetch all the collections in your current project using
```sh
appwrite init collection
```

The CLI also comes with a convenient `--all` flag to perform both these steps at once using

```sh
appwrite init --all
```

### Creating and deploying cloud functions

The CLI makes it extremely easy to create and deploy Appwrite's cloud functions. Initialise your new function using

```
$ appwrite init function
? What would you like to name your function? My Awesome Function
? What runtime would you like to use? Node.js (node-15.5)
✓ Success 
```

This will create a new function `My Awesome Function` in your current Appwrite project and also create a template function for you to get started.

```sh
$ tree My\ Awesome\ Function 

My Awesome Function
├── README.md
├── index.js
├── package-lock.json
└── package.json

0 directories, 4 files
```

You can now deploy this function using 

```sh
$ appwrite deploy function

? Which functions would you like to deploy? My Awesome Function (61d1a4c81dfcd95bc834)
ℹ Info Deploying function My Awesome Function ( 61d1a4c81dfcd95bc834 )
? Enter the entrypoint command node index.js
✓ Success Deployed My Awesome Function ( 61d1a4c81dfcd95bc834 )
```

Your function is now ready to be executed on your Appwrite server!

### Deploying Collections

Similarly, you can deploy all your collections to your Appwrite server using 

```sh
appwrite deploy collections
```

The `deploy` command also comes with a convenient `--all` flag to deploy all your functions and collections at once.

```sh
appwrite deploy --all
``` 

> ### Note
> By default, requests to domains with self signed SSL certificates (or no certificates) are disabled. If you trust the domain, you can bypass the certificate validation using
```sh
$ appwrite client --selfSigned true
```

## 📈 Usage

The Appwrite CLI follows the below general syntax.
```sh
$ appwrite [COMMAND] --[OPTIONS]
```

Let's consider some example usages of the CLI. 

### Create and List Users
Let's say you want to create a new user in your project. Prior to the CLI, you would have to get the Server/ Client SDK, setup you environment for the language you have chosen etc. With the CLI, you just do 

```sh
$ appwrite users create --userId "unique()" --name "Hugh Jackman" --email hugh@jackman.com --password helloworld
```

And you can view your created users using 
```sh
$ appwrite users list 
```

![Appwrite users list](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e5ssun9rrbueh6knyh09.png)

At any point, if you would like to change your server endpoint, key or selfSigned preferences, you can make use of the `client` command

```sh
$ appwrite client --endpoint http://192.168.1.6/v1
$ appwrite client --key 23f24gwrhSDgefaY
$ appwrite client -selfSigned true
```

## 🤕 Help

If you get stuck anywhere, you can always use the `help` command to get the usage examples. 

To get information about the different services available, you can use 
```sh
$ appwrite help
```

To get information about a particular service and the commands available in a service you can use 
```sh
$ appwrite users help
$ appwrite accounts help
```

![Appwrite Users Help](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6gtma5npsayd8r3dz0o1.png)
 
To get information about a particular command and the parameters it accepts, you can use

```sh
$ appwrite users list --help
$ appwrite account get --help 
```

If you have unanswered questions feel free to hop onto our [Discord server](https://appwrite.io/discord). We have a super active community always waiting for your questions and feedback!

## 📚 References
* [Appwrite Docs](https://appwrite.io/docs)
* [Appwrite CLI](https://appwrite.io/docs/command-line)