Google Serverless with Firebase quick start

Firebase

Basic usage

1
2
3
4
5
6
7
8
9
10
11
# install firebase-cli
yarn global add firebase-tool

# login
firebase login

# create project, that will generate files
firebase init

# deploy your app
firebase deploy

API

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// cdn
<script src="https://www.gstatic.com/firebasejs/4.9.0/firebase.js"></script>
<script src="https://www.gstatic.com/firebasejs/4.9.0/firebase-firestore.js"></script>

// js
var db = firebase.firestore();
firebase.initializeApp({
apiKey: 'AIzaSyAaJ-xa21TAN8f8PbEubfMTh1234567890',
authDomain: 'helloworld-11594.firebaseapp.com',
projectId: 'helloworld-11594'
});

// read data
db.collection("device").get().then((querySnapshot) => {
querySnapshot.forEach((doc) => {
console.log(doc.data());
});
});

// write data
db.collection("user").add({
first: "Ada",
last: "Lovelace",
born: 1815
})
.then(function(docRef) {
console.log("Document written with ID: ", docRef.id);
})
.catch(function(error) {
console.error("Error adding document: ", error);
});

Reference

https://console.firebase.google.com
https://firebase.google.com/docs/firestore/query-data/listen