Top Banner
Firebase defines for everyone By Apaichon Punopas
28

Firebase slide

Feb 10, 2017

Download

Software

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Firebase slide

Firebase defines for everyoneBy Apaichon Punopas

Page 2: Firebase slide

• Realtime Database call by API

• Store as JSON format

• Sync data from multiple applications

• Only write front end code

• Secure and monitor your data

• Access from everywhere

What is Firebase ?

Page 3: Firebase slide

• Originally referring to "non SQL", "non relational" or "not only SQL"

• Simplicity of design, simpler "horizontal" scaling to clusters of machines

• key-value, wide column, graph, or document

• "more flexible" than relational database tables

• Most NoSQL stores lack true ACID transactions

• Most NoSQL use JSON format

What is NO SQL ?

Page 4: Firebase slide

• This model organizes data into one or more tables (or "relations") of columns and rows, with a unique key identifying each row. Rows are also called records or tuples.

What is Relational DB ?

Page 5: Firebase slide

• Move fast

• Forget about infrastructure

• Make smart, data-driven decisions

• Work across platforms

• Free to start, scale with ease

Why use Firebase ?

Page 6: Firebase slide

Who use Firebase ?

Page 7: Firebase slide

• Single JSON format

Firebase structure

{"firstName":"John", "lastName":"Doe" , "age":30 , "gender":"M" , “birthDay":"1/1/1986" }

Page 8: Firebase slide

• Go to https://www.firebase.com/

• Click

• Click

• Fill Project Information

Register Firebase

Page 9: Firebase slide

Manual edit data

Page 10: Firebase slide

• Node.js is a server-side platform.

• Built on Google Chrome's JavaScript Engine (V8 Engine).

• It was developed by Ryan Dahl in 2009.

• It is an open source.

• Cross-platform runtime environment for developing server-side and networking applications.

• Node.js uses an event-driven, non-blocking I/O model.

What is NodeJS ?

Page 11: Firebase slide

• The term I/O is used to describe any program, operation or device that transfers data to or from a computer and to or from a peripheral device.

What is I/O ?

Page 12: Firebase slide

• Most I/O requests are considered blocking requests, meaning that control does not return to the application until the I/O is complete. The delayed from systems calls such read() and write() can be quite long. Using systems call that block is sometimes call synchronous programming.

What is Blocking I/O ?

Page 13: Firebase slide

• Programs that use non-blocking I/O tend to follow the rule that every function has to return immediately, i.e. all the functions in such programs are nonblocking. Thus control passes very quickly from one routine to the next.

What is non blocking I/O ?

Page 14: Firebase slide

1. Go to https://nodejs.org/en/download/

2. Choose NodeJS for your OS.

3. Extract file and Click on Installer package.

4. After finish installed then open terminal and type command.

Installation NodeJS

>node -v

Page 15: Firebase slide

1. Create file name package.json

Integrate Firebase with NodeJS #2

{ "name": "testfirebase", "version": "1.0.0", "description": "MyService is Rest Api Application for our core system.", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "keywords": [ "Test Firebase" ], "author": “Your Name", "license": "MIT", "dependencies": { "body-parser": ">= 1.14.2", "express": "^4.14.0", "firebase": "^3.5.2", "guid": "latest"

} }

Page 16: Firebase slide

2. Install NodeJS Package

3. Create file name “app.js” and put code following.

Integrate Firebase with NodeJS

>npm install

var express = require("express"); var app = express();

require('rootpath')(); var bodyParser = require('body-parser'); app.use(bodyParser.json());

app.listen(3000); console.log("My Service is listening to port 3000.");

Page 17: Firebase slide

4. Go to Firebase console and copy code for web on overview section then paste to app.js .

Integrate Firebase with NodeJS

var firebase = require("firebase"); // Initialize the app with a service account, granting admin privileges firebase.initializeApp({ apiKey: "AIzaSyBrzkaCzORJfYizrjeIij3rbl6d-EYswt0", authDomain: "ibcrm-b1a74.firebaseapp.com", databaseURL: "https://ibcrm-b1a74.firebaseio.com", storageBucket: "ibcrm-b1a74.appspot.com", messagingSenderId: "810901210082" });

Page 18: Firebase slide

1.Put code in app.js following.

2. Open Terminal then run nodejs > node app.js

Create data

var Guid = require('guid'); app.post('/members/add',function(req,res){ var _guid = Guid.create(); var guid = _guid.toString(); firebase.database().ref('members/' + guid.toString()) .set(req.body,function(err){ var message ={code:200,status:"Insert completed"} if(err) message ={code:500,status:"error",message:err} else message.result = req.body; res.send(message);

}); });

Page 19: Firebase slide

ObjectiveInstall Chrome Postman for test Restful API. 1. Find in Google by wording is “Chrome Postman”

2. Click add chrome plugin

Install Postman

Page 20: Firebase slide

ObjectiveTest CRUD Rest API by Postman to make sure that all function are work correctly . 1. Open “Chrome Postman” then set parameter following.

Setup Postman’s Parameters

1

2

3

4

2

Page 21: Firebase slide

1.Go to Firebase web console then set JSON following.

Open Authorise

Page 22: Firebase slide

• Rerun app.js

• Back to Chrome Postman then click send button.

Test Rest API

>node app.js

Page 23: Firebase slide

We have created solution like below picture.

What we’ve done ?

23

Page 24: Firebase slide

1.Put code in app.js following.

2. Open Terminal then run nodejs > node app.js

3. On Chrome Postman click Send button.

Get data

app.get('/members/getMany',function(req,res){ firebase.database().ref('members').once('value') .then(function(data){ res.send(data.val()); }) });

Page 25: Firebase slide

1.Put code in app.js following.

2. Open Terminal then run nodejs > node app.js

Edit dataapp.put('/members/edit',function(req,res){ var memberId = req.body.memberId; var memberInfo = req.body.memberInfo; firebase.database().ref('members/' + memberId) .update(memberInfo,function(err){ var message ={code:200,status:"Update completed"} if(err) message ={code:500,status:"error",message:err} else message.result = req.body; res.send(message);

}); });

Page 26: Firebase slide

1.Put code in app.js following.

2. Open Terminal then run nodejs > node app.js

Delete dataapp.delete('/members/delete',function(req,res){ var memberId = req.body.memberId; firebase.database().ref('members/' + memberId) .remove(function(err){ var message ={code:200,status:"Remove completed"} if(err) message ={code:500,status:"error",message:err} else message.result = req.body; res.send(message);

}); });

Page 27: Firebase slide

Human are social animals

Give and Take:

Why Helping Others Drives Our Success

END

Page 28: Firebase slide

Delete