Rensi Arteaga Copari
Rensi Arteaga Copari

Reputation: 76

In firebase How can I create a realtime from nodejs code

In firebase, How can I create a realtime-database from nodejs code,

I already realize created a GCP, and add firebase with the next code,

  private async  getAuthToken(file : string) {
      const auth = new google.auth.GoogleAuth({
          keyFile: file,
          scopes: scopes,
      });
      return auth;
  }

  private async  createCGP(auth:any, resource: any) {

      const request = {
          resource: resource,
          auth: auth
      };

      try {
          const response = (await cloudresourcemanager.projects.create(request)).data;
          return { success: true, resp: response };
      } catch (err) {
          return { success: false, resp: err, msg: 'error on create GCP' };
      }

    }

   private async  addFirebaseToCGP(auth:any, projectId:any, resource: any) {

        const request = {
            "project": 'projects/' + projectId,
            "resource":resource,
            auth: auth
        };
        try {
            const response = (await  firebase.projects.addFirebase(request)).data;
            console.log(response.data);

            return { success: true, resp: response };
        } catch (err) {
            return { success: false, resp: err , msg: 'error on add firebase'};
        }

    }

    

    private async  getOperationStatus(auth:any, operationName:any) {

        const request = {
            name: operationName,
            auth: auth,
        };
        try {
            const response = (await cloudresourcemanager.operations.get(request)).data;
            return { success: true, resp: response };
        } catch (err) {
            return { success: false, resp: err, msg: 'error on get operation' };
        }
    }
 
 

now I need to create a real-time database for my project.

Do you have any suggestions? , I didn't find any documentation only this link but it doesn't work

https://cloud.google.com/appengine/docs/admin-api/reference/rest/v1/apps/create?apix_params=%7B%22resource%22%3A%7B%22databaseType%22%3A%22CLOUD_DATASTORE%22%2C%22id%22%3A%22project-jaime-113%22%2C%22locationId%22%3A%22us-central%22%7D%7D

Upvotes: 1

Views: 51

Answers (1)

DIGI Byte
DIGI Byte

Reputation: 4174

Realtime Database is a part of the Firebase suite of tools and while managed on top of the GCP service, uses its own set of modules.

With node, this is often done with the admin-sdk but this can leave security vulnerabilities if this is a client app.

Admin-sdk setup with Realtime DB

On the other hand, the web packs can work in node as well

Firebase App with realtime DB

Upvotes: 1

Related Questions