Todd
Todd

Reputation: 179

Cloud functions - Cant see my functions deployed into firebase console

I'm new to Firebase functions and I'm loving them so far !! But I run with a little problem and I have some questions.

Following the read and write guide with node js for Realtime Database, my goal for now is just read a value from the database, I'm trying to get in touch with the javascript syntax to work with this awesome tool.

Now, I did this little function that just reads a value inside my database

const functions = require('firebase-functions'); 
const admin = require('firebase-admin'); 
admin.initializeApp(); //init firebase admin

//Creating my ref
var db = admin.database();
var ref = db.ref("Test/name"); 

//Getting the results just once
ref.once("value", function(snapshot)  {

    console.log(snapshot.val());

}, function(error){
    console.log(error.val());
});

Now , if I run firebase-deploy with this code it just works nice and the deploy its done but when I go to firebase console - functions, there is no functions created and I cant even see them insode google cloud functions page too.

That is my first problem. Now, I have some questions.

First , I get from the esLint this while deploying

0 errors, 2 warnings potentially fixable with the `--fix` option.

how do I use --fix to let esLint fix the warnings by itself ?

Second: Since Im using visual code to write and see my code, I would love to know if there is any shortcut to close functions automatically, like when we press enter after { in java.

Third: Is there any good tutorials on javascript syntax that can make me learn a little better and understand better javascript to deploy production code?

Thanks in advance !

Upvotes: 1

Views: 1723

Answers (1)

sketchthat
sketchthat

Reputation: 2688

The code snippet you've shared isn't a valid firebase cloud function.

If you look at the examples on github, you'll see that you need to define a trigger for the cloud function. Is it triggered off a HTTP Request, PubSub, Real Time Database Write/Update/Delete/Create. There are a lot of different options.

You also need to give your function a name, so it can be setup correctly in Firebase.

If I follow your snippet correctly it looks like you're trying to get the value of /test/name an example function to show you the value of /test/name when it changes is.

const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();


exports.testNameChange = functions.database.ref('/test/name')
  .onWrite(change => {
    // Get the snapshot of `/test/name`
    if (change.after.exists()) {
      const snapshot = change.after.val();

      // Log that value.
      console.log(snapshot);
    } else {
      console.log('Record Deleted');
    }
  });

Upvotes: 4

Related Questions