# Setup Backend - Cloud Functions

{% hint style="warning" %}
if you did not deploy Cloud Functions you will see no users. [more info](https://teamxdevelopers.gitbook.io/superchat_doc/get-started/notes-and-troubleshooting)
{% endhint %}

{% hint style="warning" %}
you should be on **Blaze Plan** to deploy Cloud Functions.
{% endhint %}

download the [NodeJS (**LTS** Version)](https://nodejs.org/en/) and install it on your Computer. then open Command Prompt or Terminal on your computer and type the command

```javascript
npm install -g firebase-tools
```

\*\* if you are on a Mac type in

```javascript
sudo npm install -g firebase-tools
```

this will install the firebase tools which is used to deploy your functions next up create a new Folder on your computer.

### CD Into the directory

now we want to execute commands within the Functions directory, to do that you can:

* if you're on Windows hold 'shift' then 'Right-click' and choose 'open command window here' to open up a command prompt in this folder OR you can use this trick to make it easier for you:

open the `'Backend - Cloud Functions'` > go the top bar > and then type in `cmd` and hit enter. this should open up a CMD window within the designated folder

![image](https://fireapp-docs.devlomi.com/images/cloud-functions-cmd.png)

* otherwise, you can just open CMD/Terminal and then type in `cd` and then drag the Backend-Cloud Functions folder and hit enter

then type the command:

```javascript
firebase login
```

this will open up the Browser on your Computer to associate the Functions on your PC with Firebase Project then type the command:

```javascript
firebase init functions
```

this will link your cloud functions with your firebase Project that you've created before. it will also create a **'functions'** directory which you will paste the files in later.

now complete the steps in command line and choose the Project that you've Created ![image](https://fireapp-docs.devlomi.com/images/firebase-cloud-functions-setup-1.png)

then choose JavaScript as the language , don't use ESLint , and don't install dependencies

now we have to deploy our functions to Firebase.

* but first you need to add your package name by going to `'Backend - Cloud Functions'` > `index.js` and open it with any text editor, then add package name in the constant `packageName`.

now copy the follwoing files:

* index.js
* push-token-sender.js
* message-sender.js
* generate-virgil-jwt.js
* package.json

  from `'Backend - Cloud Functions'` folder and paste them in the project folder that you've created in 'functions' directory and replace them
* assuming your cmd is already in 'Backend - Cloud Functions' folder, type in the command `cd functions`
* then type the command

```javascript
npm install
```

* finally run the command

  ```javascript
  firebase deploy
  ```

you should see something like this if deploy process was succeeded(Note that it should SHOW ALL functions Names)

![image](https://fireapp-docs.devlomi.com/images/firebase-cloud-functions-setup-2.png)

sometimes a network error may occur and functions may be partially deployed, if that happened it will show up in the CMD.

to fix that just copy these lines highlighted by CMD and paste it in

![image](https://fireapp-docs.devlomi.com/images/cloud-functions-error-fix-cmd.png)
