<commit_before># NativeScript Firebase plugin

<img src="docs/images/firebase.png" width="154px" height="43px" alt="Firebase"/><br/>
Google's realtime app platform (Database, Authentication, Configuration, Notifications) [firebase.google.com](https://firebase.google.com/)



If you can spare 41 seconds, check this plugin's [demo app](https://github.com/EddyVerbruggen/nativescript-plugin-firebase-demo) in action:
[![YouTube demo, 41 sec](docs/images/yt-thumb.png)](https://youtu.be/7zYU5e0Djkw "YouTube demo, 41 sec")

### Use when
* you need to store JSON data in the cloud (but don't want to loose data when the device is offline),
* you want to sync that data to other devices and platforms,
* you want to optionally protect that data by having users log in,
* you want to update clients at the moment the data changes (think chat and multiplayer games),
* you want an easy way to remotely configure app features,
* you want push notifications.

## Prerequisites
Head on over to [https://console.firebase.google.com/](https://console.firebase.google.com/) and sign up for a free account.
Your first 'Firebase' will be automatically created and made available via an URL like `https://n-plugin-test.firebaseio.com`.

Open your Firebase project at the Google console and click 'Add app' to add an iOS and / or Android app. Follow the steps (make sure the bundle id is the same as your `nativescript.id` in `package.json` and you'll be able to download:

* iOS: `GoogleService-Info.plist` which you'll add to your NativeScript project at `app/App_Resources/iOS/GoogleService-Info.plist`

* Android: `google-services.json` which you'll add to your NativeScript project at `platforms/android/google-services.json`

## Installation
From the command prompt go to your app's root folder and execute:

```
tns plugin add nativescript-plugin-firebase
```

### Start-up wiring
We need to do some wiring when your app starts, so open `app.js` and add this before `application.start();`:

```js
var firebase = require("nativescript-plugin-firebase");
```

_Note that if you previously (before plugin version 3.3.0) added some other code for this plugin to `app.js` you can now go ahead and remove it._


### Android
Install packages 'Google Play Services' and 'Google Repository' in your [Android SDK Manager](http://stackoverflow.com/a/37310513)

#### Open `app/App_Resources/Android/app.gradle`
- Add `applicationId "com.example.app"` to the `defaultConfig` node (change the id to the same as in your app's `package.json`), so it becomes:

```
android {
    ...
    defaultConfig {
        applicationId "com.example.app"
        ...
    }
}
```

#### Open `platforms/android/build.gradle`
- Near the top there's a dependencies section, add `classpath "com.google.gms:google-services:3.0.0"` so it becomes something like:
```
  dependencies {
    classpath "com.android.tools.build:gradle:1.5.0"
    classpath "com.google.gms:google-services:3.0.0"
  }
```
- Add the very bottom of the same file add `apply plugin: "com.google.gms.google-services"`

## Usage

If you want a quickstart, [clone our demo app (an older version is used in the YouTube video)](https://github.com/EddyVerbruggen/nativescript-plugin-firebase-demo).

### init
```js
  var firebase = require("nativescript-plugin-firebase");

  firebase.init({<commit_msg>doc++<commit_after># NativeScript Firebase plugin

<img src="docs/images/firebase.png" width="154px" height="43px" alt="Firebase"/><br/>
Google's realtime app platform (Database, Authentication, Configuration, Notifications) [firebase.google.com](https://firebase.google.com/)



If you can spare 41 seconds, check this plugin's [demo app](https://github.com/EddyVerbruggen/nativescript-plugin-firebase-demo) in action:
[![YouTube demo, 41 sec](docs/images/yt-thumb.png)](https://youtu.be/7zYU5e0Djkw "YouTube demo, 41 sec")

### Use when
* you need to store JSON data in the cloud (but don't want to loose data when the device is offline),
* you want to sync that data to other devices and platforms,
* you want to optionally protect that data by having users log in,
* you want to update clients at the moment the data changes (think chat and multiplayer games),
* you want an easy way to remotely configure app features,
* you want push notifications.

## Prerequisites
Head on over to [https://console.firebase.google.com/](https://console.firebase.google.com/) and sign up for a free account.
Your first 'Firebase' will be automatically created and made available via an URL like `https://n-plugin-test.firebaseio.com`.

Open your Firebase project at the Google console and click 'Add app' to add an iOS and / or Android app. Follow the steps (make sure the bundle id is the same as your `nativescript.id` in `package.json` and you'll be able to download:

* iOS: `GoogleService-Info.plist` which you'll add to your NativeScript project at `app/App_Resources/iOS/GoogleService-Info.plist`

* Android: `google-services.json` which you'll add to your NativeScript project at `platforms/android/google-services.json`

## Installation
From the command prompt go to your app's root folder and execute:

```
tns plugin add nativescript-plugin-firebase
```

### Android
Install packages 'Google Play Services' and 'Google Repository' in your [Android SDK Manager](http://stackoverflow.com/a/37310513)

#### Open `app/App_Resources/Android/app.gradle`
- Add `applicationId "com.example.app"` to the `defaultConfig` node (change the id to the same as in your app's `package.json`), so it becomes:

```
android {
    ...
    defaultConfig {
        applicationId "com.example.app"
        ...
    }
}
```

#### Open `platforms/android/build.gradle`
- Near the top there's a dependencies section, add `classpath "com.google.gms:google-services:3.0.0"` so it becomes something like:
```
  dependencies {
    classpath "com.android.tools.build:gradle:1.5.0"
    classpath "com.google.gms:google-services:3.0.0"
  }
```
- Add the very bottom of the same file add `apply plugin: "com.google.gms.google-services"`

## Usage

If you want a quickstart, [clone our demo app (an older version is used in the YouTube video)](https://github.com/EddyVerbruggen/nativescript-plugin-firebase-demo).

### Start-up wiring
We need to do some wiring when your app starts, so open `app.js` and add this before `application.start();`:

```js
var firebase = require("nativescript-plugin-firebase");
```

_Note that if you previously (before plugin version 3.3.0) added some other code for this plugin to `app.js` you can now go ahead and remove it._

### init
```js
  var firebase = require("nativescript-plugin-firebase");

  firebase.init({
{'fraction_non_alphanumeric': 0.11568007230004519, 'fraction_numerical': 0.0102425064015665, 'mean_word_length': 4.433715220949264, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 14, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3643061', 'n_tokens_mistral': 2051, 'n_tokens_neox': 1937, 'n_words': 745}