I have a node
project created with Vue
using Firebase Hosting
, Cloud Functions
and Firestore
.
I can deploy locally with npm run build | firebase serve
. In the Vue
app I'm calling a Cloud Function with firebase.functions().httpsCallable('placeOrder').then((result) => {...})
A
Is it possible to make it so that the Function
call calls the Functions emulator
(running on port 5001
) and I can step through the code with breakpoints?
B
If it's not possible to call the emulator from the locally hosted site, how can I do Cloud Functions
development locally? I've read a bunch of articles, but they seem to be outdated. I can emulate a function with the Functions Framework and get the logs when I call it, but I'm not sure how to attach a debugger to it. Also, what happens if that Function
reads / writes Firestore
? Will it read / write the emulated one?
Cheers
I'll tell you what had worked for me. I love firebase but, using the local emulators has been kind of like a pain for me. I know it will get better with time but is not there yet. Maybe someone else can give us a better approach
Use express and serve your function in the port 5001. You can attach the debugger to use breakpoints. Check here.
Folder structure
index.js
app.js
serve.js
Unit testing will make your life easier when dealing with cloud functions. They will make you save time and they will make you a better programmer at the same time.
Note: in this case, you are actually using the firestore database, so make sure you have a development environment. If you ever use the emulator for firestore it's in your local machine so it doesn't write to the real database. Hope that helps