Learn JavaScript Promises (Pt.1) with HTTP Triggers in Cloud Functions - Firecasts

preview_player
Показать описание
In this Firecast, Doug Stevenson covers programming with JavaScript Promises in an HTTP trigger in Cloud Functions.

If you’re going to write code for Cloud Functions, you definitely need to know about how promises work. Nearly all the functions you write will use promises, and, if you don’t do it correctly, your code may fail in mysterious ways. In this tutorial, you’ll learn the basics of using promises in your HTTP functions.

Рекомендации по теме
Комментарии
Автор

Doug, your contributions to the dev community are superb and most definitely appreciated! Keep up the great work!

ndipatri
Автор

Thanks so much for these videos! I'm so impressed with the documentation the Firebase team has put together, especially videos like this that go beyond explaining how Firebase works, but actually teach more basic Javascript concepts. Such a great resource!

RiceCodes
Автор

You are very talented to explain things. Very good job Doug! ☺️

pierrechavaroche
Автор

He often answers my questions on SO with Frank, the master. Thank you all, sincerely [:

teamexit
Автор

Love the videos on Cloud Functions. Keep 'em coming.

yogenp
Автор

Great video, the speaker is very friendly, speaks at a good pace and speaks clearly. First video ever on promises, so very glad you made this! Thanks!

clearwavepro
Автор

Congrats Doug and the Firebase team in general! This firebase serve... thing is so good!!!

fotios
Автор

Thanks.. For being more informative & more patient than the last similar video made by Jen Person. This made stuff much more clear. Way to go

lgopt
Автор

Thanks Doug!! Everything was so incredibly clear. You make these sound so easy.

robertosoriano
Автор

@3:17, admin.initializeApp() but how come we don't need to add the firebaseConfig like

var firebaseConfig = {
apiKey: "AIza...",
authDomain: "name...",
databaseURL: "https://...",
projectId: "id...",
storageBucket: "Bucket...",
messagingSenderId: "1...",
appId: "...",
measurementId: "G-..."
};
// Initialize Firebase

fotios
Автор

Not sure why but when I attempt to run the function locally I get {} as the response and the following error in the firebase-debug.log: "Error: Could not load the default credentials." Yet when I deploy the function it works fine, returning the object from Firestore. Looking at the docs it seems that when running locally functions and Firestore should already have the permissions necessary. Tried creating a service key and passing that to admin.initializeApp but same result. Any ideas?

MattPenner
Автор

For those that are facing problems to run locally (not authenticated problem): Go the project settings in your firebase console / service accounts and click in the button "generate new primary key", save the file.
In the code initialize your function like this:

const serviceAccount =
admin.initializeApp({ credential: })

admin.json is the file that you download (pay attention to the json file path).
In the beginning, when we create the project, where we choose "functions" in the console I also have chosen firebase emulator (I think it's necessary in the most recent versions to run locally)

FelipeTrovadeAraujo
Автор

Thank you sir! Great content, easy to follow. Love Firebase ;) Cheers!

navieses
Автор

Can I have the referencing videos using JavaScript rather than type script

lakshmisravyagajavalli
Автор

With the latest firebase admin - you have to set up your service account key :

import * as admin from 'firebase-admin';
var serviceAccount = require('path to your key here');
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: 'Your database URL',
});

resonancerealty
Автор

Thank you very much! This is way easier than reading docs.

titaniumwolf
Автор

Quick question guys, how would you actually then test the local function -> Lets say an onRequest function needs a payload, would you add your payload to the end of the url? And is it working on your database directly at google (not local)? Really need to know how to get the local testing setup working. Thank you

wesleybarnes
Автор

Thank Doug!
Shouldn't you return the promise at the end?

salahxx
Автор

When I try on localhost I get an empty object { }. But it works fine if I deploy it...

fotios
Автор

wow, its very use full to us, Thank you sir

mayursoftwarewalaa