Git Product home page Git Product logo

algolia-firebase-functions's Introduction

Algolia <-> Firebase cloud functions

npm Tests Codacy Badge

Useful library to keep your Firebase Database of Firebase Cloud Firestore data in sync with Algolia for easy search.

Starting from version 2.0, this library supports Cloud Functions v1.0. If you need to support beta Cloud Functions, use version 1.0.3 instead.

Starting from version 4.0.0, this library supports Node 10 and no longer supports Node 8. If you still need to support Node 8, use version 3.3.0 instead.

Installation

In your functions directory:

 npm install --save algolia-firebase-functions

Usage

To use this library in your Functions, first of all you need to set environmental variables for Algolia to initialize connection. Grab your API keys here first.

Open Terminal, go to your functions directory and input these commands:

firebase functions:config:set algolia.app="<YOUR-ALGOLIA-APP-ID>"
firebase functions:config:set algolia.key="<YOUR-ALGOLIA-APP-PUBLIC-KEY>"
firebase functions:config:set algolia.index="<YOUR-ALGOLIA-INDEX-NAME>"

Then, in your functions' index.js file, paste the following lines:

const algoliasearch = require('algoliasearch');
const algoliaFunctions = require('algolia-firebase-functions');

const algolia = algoliasearch(functions.config().algolia.app,
                              functions.config().algolia.key);
const index = algolia.initIndex(functions.config().algolia.index);

exports.syncAlgoliaWithFirebase = functions.database.ref('/myref/{childRef}').onWrite(
   (change, context) => algoliaFunctions.syncAlgoliaWithFirebase(index, change);
);

If you're using Firebase Cloud Firestore, you can use the following code:

exports.syncAlgoliaWithFirestore = functions.firestore.document('/myDocument/{childDocument}').onWrite(
   (change, context) => algoliaFunctions.syncAlgoliaWithFirestore(index, change);
);

And redeploy your functions:

firebase deploy --only functions

Now, after any changes made with your references, it will be sent to Algolia, so you'll be sure that users can search on the newest data.

algolia-firebase-functions's People

Contributors

amv-bamboo avatar dependabot-preview[bot] avatar dependabot[bot] avatar fobo66 avatar yuriploc avatar

Watchers

 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.