#community-help

Setup and Issues in Connecting Typesense Instance with Firebase Emulator

TLDR Michael.M seeks help on connecting a local Typesense instance to the Firebase local emulator. Jason suggests looking at emulator commands and creating a specific file. After various attempts and troubleshooting steps, Michael.M is able to establish the connection.

Powered by Struct AI

2

1

1

17
18mo
Solved
Join the chat
May 03, 2022 (18 months ago)
Michael.M
Photo of md5-0d6b77b41964b2e6a4e556e7d2ce9376
Michael.M
09:15 PM
Hello everyone, I’m brand new to Typesense. Working on an implementation for an application using React and Firebase. Most of the pieces of implementation make sense, however I’m struggling to understand how to connect a local Typesense instance to the Firebase local emulator for development.

This screenshot from the firestore-typesense-search docs is the only indication of using the emulator, but it doesn’t explain how Typesense will watch for changes to my emulator database (or is that even possible?). I am able to run the emulator, and I’m able to run a local copy of Typesense, but I’m not able to connect the two.

I understand that I could probably just make a bunch of cloud functions that watch the data, but I was hoping to get those “sync” updates automatically so I can maintain the same code between dev and production.

Thanks in advance for any help!
09:26
Jason
09:26 PM
You want to create a file called test-params.env using this file as an example: https://github.com/typesense/firestore-typesense-search/blob/master/test-params.local.env
09:27
Jason
09:27 PM
This is what configures the extension within the emulator. No additional steps are required...
Michael.M
Photo of md5-0d6b77b41964b2e6a4e556e7d2ce9376
Michael.M
09:46 PM
Thank you so much. I appreciate that information. I’ll try this out now
10:08
Michael.M
10:08 PM
Unfortunately I’m running into an issue. When I run npm run emulator within firestore-typesense-search I receive an error that says: error: unknown option '--test-params' I have created a test-params.env and filled out the information. I’m unable to find any information about the --test-params option in the firebase CLI documentation. Here are the steps I took:

1. clone firestore-typesense-search
2. install npm packages
3. create test-params.env file and fill in information
4. run npm run emulator
Running the typesenseServer script worked perfectly.
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
10:27 PM
I think those flags are only enabled after running these two commands: https://github.com/typesense/firestore-typesense-search/blob/1b9d22bc1e3fbb55fd548003abbadcbf2be8a3fc/.circleci/config.yml#L13-L18

Could you install them and then try again?
Michael.M
Photo of md5-0d6b77b41964b2e6a4e556e7d2ce9376
Michael.M
10:30 PM
Ok, running those installs seemed to work. I think the second one was the missing piece for me.

1

10:31
Michael.M
10:31 PM
I’ll continue testing the initial suggestions you gave to see if everything is working.

1

May 04, 2022 (18 months ago)
Michael.M
Photo of md5-0d6b77b41964b2e6a4e556e7d2ce9376
Michael.M
08:35 PM
Hello Jason I appreciate all your help yesterday. I was able to get to a point where I can play around with the collections within the running Typesense server (using the extension locally). I also imported my own data through the --import=... option in the emulator script (instead of the default “books” data). However, even though my data is populating properly in the extension’s firestore instance, I am not able to retrieve it from the Typesense data store. I am running this code in a separate file:

//typesense-test.js

const Typesense = require('typesense')

async function main() {
  let client = new Typesense.Client({
    'nodes': [{
      'host': 'localhost',
      'port': '8108',
      'protocol': 'http'
    }],
    'apiKey': 'xyz',
    'connectionTimeoutSeconds': 2
  })

  const test = await client.collections().retrieve()
  console.log(test)
}

main()

And I receive [] in the console. I have set up the test-params.env correctly, but still nothing is populated.

I’m running both the extension emulator and the typesense server, and then I run the node typesense-test.js in a separate location.
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
08:38 PM
Michael.M The extension does not create the Typesense Collection for you. Instead it syncs data to a Typesense collection you've already created. So you'd need to create the collection first using the Typesense API (since you're using localhost)
08:39
Jason
08:39 PM
Also, I suspect that the import option in the emulator doesn't trigger the extension's functions. Could you instead try creating / updating Firestore documents via the emulator, once you've created the Typesense Collection?
Michael.M
Photo of md5-0d6b77b41964b2e6a4e556e7d2ce9376
Michael.M
08:39 PM
Ah I see. Yes I’ll try that
09:23
Michael.M
09:23 PM
Ahh finally figured out the problem. I had forgotten to install the extension cloud functions npm packages. Not the first time that has happened 😂
09:24
Michael.M
09:24 PM
I was able to log a document to the typesense data store
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
09:24 PM
Ahh! Awesome!
Michael.M
Photo of md5-0d6b77b41964b2e6a4e556e7d2ce9376
Michael.M
09:26 PM
I’m going to summarize the process for getting this setup, and I’ll try to put together an MR to update the README with more information

2