Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
824 views
in Technique[技术] by (71.8m points)

node.js - Running node index.js does nothing

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

enter image description here

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...