Giter Club home page Giter Club logo

firebase's Introduction

install Firebase tools

> npm i -g firebase-tools
'''

check if it install if it response to the command ```> firebase ```

login

firebase login

**Local Firebase project**: create a project, cd to that directory and then:

firebase init

selecgt the tool you like:
 ◯ Database: Deploy Firebase Realtime Database Rules
 ◯ Firestore: Deploy rules and create indexes for Firestore
❯◯ Functions: Configure and deploy Cloud Functions
 ◯ Hosting: Configure and deploy Firebase Hosting sites
 ◯ Storage: Deploy Cloud Storage security rules

After editing the project, go to [console.firebase]https://console.firebase.google.com select functions because this is what we initiated, and copy the project ID from the url. example" https://console.firebase.google.com/u/0/project/one-time-password-b07e6/functions/list the project id is one-time-password-b07e6

deploy: local to remote project:

> firebase deploy --project one-time-password-b07e6

Now we can edit functions in remote project, in functions section. the output will be displayed url:

Function URL (helloWorld): https://us-central1-one-time-password-b07e6.cloudfunctions.net/helloWorld

Inside the local project, in functions folder, index.js every time we call expende with a name following, it will become as the name of a function.

exports.helloWorld = functions.https.onRequest((request, response) => {
 response.send("Hello from Firebase!");
});

hellloWorld is the name of the function that will apear in firbase console. the output "Hello from Firebase" will be show in the url: https://us-central1-one-time-password-b07e6.cloudfunctions.net/helloWorld

if you get error, link the project in local to the relevant project in remote before deplying:

> firebase use --add
(select project from the list)

and then just firebase deploy

inorder to crete function on dedicated filr we create a file inside function directory in our local firbase project. let call it "create_user.js"

module.exports = function(req, res) {
    res.send(req.body);
};

and in index.js:

const createUser = require('./create_user');
exports.createUser = functions.https.onRequest(createUser);

Then just post with postman to create_user function url an object and it will be eco back as aresponse

inorder to create service manager to get access to firebase database we need in index.js to add:

const admin = require('firebase-admin');

admin.initializeApp({
    credential: admin.credential.cert(serviceAccount),
    databaseURL: "https://one-time-password-b07e6.firebaseio.com"
  });

and to generate private key from console.firebase, from proget settings>Service accounts>generate new private key then open the downloaded file, and paste its conent to new create file under functions folder, name the file "service_acount.json". now we can import the file to index.js as "serviceAcount"

const serviceAccount = require('./service_acount.json');

(add that before the call admin.credential.cert(serviceAccount))

firebase's People

Contributors

zoharios avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.