I am trying to follow a simple tutorial on setting up algolia which one can find here.
https://www.algolia.com/doc/tutorials/indexing/3rd-party-service/firebase-algolia/
I literally copy the code word for word into an index.js file.
When I run node index.js in my terminal I get this
No success message. Nothing in algolia. Nothing. I have included my code is there anything that anyone noties that I may have done wrong. This has been frustrating me for hours.
const algoliasearch = require('algoliasearch');
const dotenv = require('dotenv');
const firebase = require('firebase');
// load values from the .env file in this directory into process.env
dotenv.load();
// configure firebase
firebase.initializeApp({
databaseURL: process.env.FIREBASE_DATABASE_URL,
});
const database = firebase.database();
// configure algolia
const algolia = algoliasearch(
process.env.ALGOLIA_APP_ID,
process.env.ALGOLIA_API_KEY
);
const index = algolia.initIndex(process.env.ALGOLIA_INDEX_NAME);
// Get all contacts from Firebase
database.ref('/events').once('value', event => {
console.log('index is', index);
// Build an array of all records to push to Algolia
const records = [];
event.forEach(event => {
// get the key and data from the snapshot
const childKey = event.key;
const childData = event.val();
// We set the Algolia objectID as the Firebase .key
childData.objectID = childKey;
// Add object for indexing
console.log('child data is', childData);
records.push(childData);
});
// Add or update new objects
index
.saveObjects(records)
.then(() => {
console.log('records are', records);
console.log('Events imported into Algolia');
})
.catch(error => {
console.error('Error when importing events into Algolia', error);
process.exit(1);
});
});
I have followed all steps in the tutorial. I even ran it again everytime I run node index.js nothing happens no matter what I do