GithubHelp home page GithubHelp logo

isabella232 / algolia-firebase-nodejs Goto Github PK

View Code? Open in Web Editor NEW

This project forked from algolia/algolia-firebase-nodejs

0.0 0.0 0.0 12 KB

An example showing how to push data from Firebase to Algolia

JavaScript 100.00%

algolia-firebase-nodejs's Introduction

algolia-firebase-nodejs example

Algolia is a nice way to make your Firebase data searchable. Out of the box you get prefix matching, typo tolerance and more advanced features like faceting and filtering. This repository contains contains example code and instructions on how to run it.

Key files

  1. importFirebaseToAlgolia.js: Shows how to do a one-time import of all Firebase data under a specific ref.
  2. syncFirebaseToAlgolia.js: Shows how to listen to changes of children of a ref and sync them to Algolia.
  3. loadFirebase.js: Loads test data into Firebase so it can be sent to Algolia later.

Prerequisites

Firebase

Create a new Realtime Database, or you can use one that already exists. We'll be using the ref "contacts" for the whole example, so make sure there isn't any data there already.

Algolia

Create a new Algolia application, or use one that already exists. We'll be creating an index called "contacts", so make sure that doesn't already exist.

Usage

Clone this repository.

git clone [email protected]:algolia/algolia-firebase-nodejs.git

Install dependencies with npm install or yarn.

yarn

Create a file called .env. Substitute your values for the placeholders:

ALGOLIA_APP_ID=<algolia-app-id>
ALGOLIA_API_KEY=<algolia-api-key>
FIREBASE_DATABASE_URL=https://<my-firebase-database>.firebaseio.com

Make sure the Algolia API key you've chosen has write access. If in doubt, use your Admin API Key.

Download a service account JSON file from Firebase. This will be used to authenticate you as an admin so you can read and write data. From the Firebase console for your database, click the gear icon and choose "Project Settings". Go to the "Service Accounts" tab. Click "Generate New Private Key". Move the downloaded file into this directory and name it serviceAccountKey.json.

This file and .env are in the .gitgnore, so you don't have to worry about accidentally checking them in.

Load example data

Load example contacts data into your Firebase database running:

node loadFirebase

Look at the code in the loadFirebase.js file to see what is happening. If this is successful, you will see a message "Contacts loaded to firebase" and you will be able to see data in your Firebase database in the console.

First-time import into Algolia

Import these contacts records into Algolia by running:

node importFirebaseToAlgolia

If this is successful, you should see "Firebase<>Algolia import done". Your contact records have been imported into Algolia and you can see them in your dashboard.

Ongoing sync to Algolia

In a real application, you will want to listen for Firebase changes and index them as they come in. To do this, run:

node syncFirebaseToAlgolia

This process will keep running indefinitely, listening for changes to the "contacts" node in your Firebase database. When it receives a change, it will add, update or delete the record in Algolia and then log to the console.

algolia-firebase-nodejs's People

Contributors

dzello avatar haroenv avatar joshed-io 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.