Search code examples
node.jsgoogle-cloud-firestoreloopbackjsnode-modules

how to configure loopback 4 with firestore datasource


I am trying to configure loopback4 with firestore data source using loopback-connector-firestore connector. when i am trying to post it is showing error code 500 with Error: Internal Server Error. Please tell me where i am exactly doing wrong.


Solution

  • It is simple.

    1. First follow the steps to create datasource running the console command lb4 datasource.
    2. When the command line ask you for the connector select other.
    3. When the command line ask you for the connector's package name paste this loopback-connector-firestore. Please note that all connector for loopback 3 must work in loopback 4.
    4. Then you should use a service account. Go to Project Settings > Service Accounts and press the Generate new private key button, in the Google Cloud Platform Console. Generate a new private key and save the JSON file.
    5. Then in the src/datasources project folder open your new datasourceName.datasource.json file and add the following keys that you can find in the downloaded JSON file from the Google Cloud Platform in the previous step:
    {
      "projectId": "",
      "clientEmail":  "",
      "privateKey": "",
      "databaseName": "Optional, Default: projectId"
    }
    

    That is all. Now, if you have models, repositories and controller previously created you can run npm start, open the explorer and test your endpoints.

    Regards.