> For the complete documentation index, see [llms.txt](https://docs.nzoni.app/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.nzoni.app/angular-firebase-node.js.md).

# Angular / Firebase / Node.js

This guide will walk you through the setup, configuration, and usage of Angular / Firebase / Node.js, a robust SaaS boilerplate designed to accelerate your SAAS

## Download repositories

Once you've purchased Nzoni, your github email account will be added to the related projects.\
Make sure you're already connected to github on your cli terminal or use Github Personal access token.

### Download Angular repository

```
git clone https://github.com/nzoni-app/nz-angular-firebase.git
```

### Download Node.js repository

```
git clone https://github.com/nzoni-app/nz-nodejs-firebase.git
```

## Firebase Configuration

Create a Firebase account if you don't have one already, by visiting firebase.google.com.

* Create a new project
* Download the service key JSON file and place it at the root of your Node.js project with the name `serviceAccountKey.json`.
* Enable Email/Password, Google, and passwordless email authentication.
* Enable Firebase and create two indexes:
  * Collection ID: `users`&#x20;
    * &#x20;`createdAt` = Ascending
    * `id` = Ascending
  * Collection ID: `plans`
    * &#x20;`active` = Ascending
    * &#x20;`position` = Ascending
* Activate Firebase storage
  * Set rules:

```bash
rules_version = '2';
service firebase.storage {
  match /b/{bucket}/o {
    match /{allPaths=**} {
      allow read;
      allow write: if request.auth != null;
    }
  }
}
```

* Set `FIREBASE_PROJECT_ID` in the `.env` file.

## Installation

#### Install Node.js (if you haven't already)

If you haven't installed Node.js yet, you can follow the instructions [here](https://nodejs.org/en/learn/getting-started/how-to-install-nodejs).

#### Install Node Modules for Angular project

Navigate to the downloaded Angular project repostiory:

```
cd nz-angular-firebase
npm install
```

#### Install Node Modules for Node.js project

Navigate to the downloaded Node.js project repostiory:

```
cd nz-nodejs-firebase
npm install
```

## Configure Environment Variables

### Node.js environnement

Node.js supports environment variables out of the box. You can set defaults in .env (for all environments), .env.development (for development), and .env.production (for production).

By default, there is the <mark style="background-color:blue;">.env.example</mark> file. Rename it to <mark style="background-color:blue;">.env</mark> modify variables

```sh
ENV=developpement
PORT=3000

# DB configuration
DB_HOST=
DB_PORT=
DB_USERNAME=
DB_PASSWORD=
DB_NAME=
DB_LOCAL=true

# Mailing
SMTP_HOST=
SMTP_PORT=
SMTP_SECURE=false
SMTP_AUTH=
SMTP_PASSWORD=
SMTP_FROM='"Support name" <support@domain.name>'

# Logs
APP_DEBUG=true
JOB_ERROR_LOG_PATH='./'
DEFAULT_LOG_PATH='./logs'

# FONT_END_URL
FRONT_END_URL=

# Mail for moderation
MODERATION_MAIL=

STRIPE_SECRET_KEY=
STRIPE_WEBHOOK_SECRET=

TRIAL_DAYS=
DEFAULT_PLAN_ID=

FIREBASE_PROJECT_ID=
```

### Angular Environnement

Edit src/environments/environnement.ts&#x20;

```typescript
export const environment = {
  production: false,
  api: '', // backend-url
  domain: '', // frontend-url
  google_tag_id: '', // for google analytics
  firebase: {
    apiKey: "",
    authDomain: "",
    projectId: "",
    storageBucket: "",
    messagingSenderId: "",
    appId: "",
    measurementId: ""
  }
}
```

## Run

### Angular

To start Angular project, simply run:

```sh
ng serve
```

Angular instance is now running at [http://localhost:4200/](http://localhost:3000/).

### Node.js

Run the following command to start the server:

```sh
npm run start
```

Node.js instance is now running at <http://localhost:3000/>.

Congratulations! Your Nzoni project  is now running!
