Algolia/Firebase - Terminal executes code then sits idle

I followed these Firebase/Algolia docs https://www.algolia.com/doc/guides/integrations/firebase-algolia/. I did a bit of tweaking as some of the initial setup instructions are outdated but I got it to work. I put all of the code from that page inside my app.js file. Inside terminal I ran ‘npm start’ and and when I checked my Algolia Indices console my Firebase data successfully got indexed. There are 2 problems though.

After running ‘npm start’ I got these print statements in this order:

node app.js

Firebase<>Algolia reimport done
Firebase<>Algolia object saved
Firebase<>Algolia import done
//terminal just sits idle from this point on

As I said the the object was indexed (I only had 1 object inside Firebase). The problem is after the final “… import done” statement, nothing happens. Terminal just sits in a state that seems as if it’s waiting for more data to be sent or more instructions to be given, it doesn’t do anything. I have to press CNTRL+C to stop it. What’s it waiting for and why doesn’t it exit on its own once it indexes everything from FB?

1 Like

My guess is that the program keeps running because the Firebase listeners are still active. If you want to do a one-time indexing, you can use once instead of on to read Firebase data. Otherwise it will keep the connection open waiting for changes.

Apologies that it took us a while to get back to you on this one. Does that help or were you able to make progress otherwise?

1 Like

@dzello thanks for getting back to me. I went to a Meetup and someone pointed out that as I added data to the database, once I queried it via Algolia it was getting indexed which meant it was still listening. This is my first time doing this so I thought it was supposed to stop once it indexed and start only if a query was triggered. I now understand it’s supposed to stay actively listening. Thanks again for your help and response! :blush::blush:

1 Like