Is there or will there be modular Firebase Admin Database functions i.e. update(), get(), set(), ref() etc.? Maybe there is a workaround?
Else I would have to code equal functions twice, like "craftBuilding()" on server (admin) and one for client.
Tried to:
import { getDatabase, ref, set, update, child, onChildAdded } from 'firebase-admin/database';
Error:
The requested module ‘firebase-admin/database’ does not provide an export named ‘ref’
I expected to be able to use firebase rtdb functions like on client-side, to not code identical functions twice.
2
Answers
Since Firebase Admin is namespaced,
ref
is available after you initialize.You could modularize it yourself by creating functions for the operations you require in a separate file:
You can read more on the admin SDK documentation.
The Admin SDK is not totally modular yet but has some function such a
getDatabase()
startingV10
.I would recommend using latest version of the SDK along with the existing syntax but use newer modular imports.