Hello everyone, I’m brand new to Typesense. Worki...
# community-help
m
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!
j
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
This is what configures the extension within the emulator. No additional steps are required...
m
Thank you so much. I appreciate that information. I’ll try this out now
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.
j
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?
m
Ok, running those installs seemed to work. I think the second one was the missing piece for me.
🙌 1
I’ll continue testing the initial suggestions you gave to see if everything is working.
👍 1
Hello @Jason Bosco 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:
Copy code
//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.
j
@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)
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?
m
Ah I see. Yes I’ll try that
Ahh finally figured out the problem. I had forgotten to install the extension cloud functions npm packages. Not the first time that has happened 😂
I was able to log a document to the typesense data store
j
Ahh! Awesome!
m
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