Importing/Adding the dependencies
First ensure that you load the firebase
SDK and then the main flamelink
app package along with any of the modules you want to you in your project.
The examples below shows you how to quickly get started. Take a look at the Advanced Installation instructions to import only what you need.
In a CommonJS environment:
var flamelink = require('flamelink')
or using ES Modules or TypeScript:
import flamelink from 'flamelink'
Note: You might need to enable the esModuleInterop
option in either your tsconfig.json
file or provided as a CLI flag when using TypeScript.
Creating your Flamelink app instance
Create your flamelink
app instance by passing in an existing firebaseApp
instance along with any other flamelink
config options:
import * as firebase from 'firebase'
import flamelink from 'flamelink'
const firebaseConfig = {
apiKey: '<your-api-key>',
authDomain: '<your-auth-domain>',
databaseURL: '<your-database-url>',
projectId: '<your-project-id>',
storageBucket: '<your-storage-bucket-code>',
messagingSenderId: '<your-messenger-id>',
}
const firebaseApp = firebase.initializeApp(firebaseConfig)
const app = flamelink({
firebaseApp, // required
dbType: 'rtdb', // can be either 'rtdb' or 'cf' for Realtime DB or Cloud Firestore
env: 'production', // optional, default shown
locale: 'en-US', // optional, default shown
precache: true, // optional, default shown. Currently it only precaches "schemas" for better performance
})
Tip: Go to your Firebase console for more info regarding the Firebase app options.
When using the firebase-admin
SDK on server-side, it is the same, you only pass in the Firebase admin app instance instead:
const admin = require('firebase-admin')
const flamelink = require('flamelink')
const serviceAccount = require('path/to/serviceAccountKey.json')
const firebaseConfig = {
credential: admin.credential.cert(serviceAccount),
databaseURL: '<your-database-url>',
storageBucket: '<your-storage-bucket-code>', // required if you want to use any Storage Bucket functionality
}
const firebaseApp = admin.initializeApp(config)
const app = flamelink({
firebaseApp, // required
// same options as above
})
You can use any of the different ways to create the admin firebaseApp instance.
Using your flamelink app
Once you have an instance of the flamelink
app, you can start using it to interact with your data stored in either your Firebase Real-time Database or Cloud Firestore. Suppose you want to retrieve all your products
created under the "Content" section in flamelink
.
const products = await app.content.get({ schemaKey: 'products' })
console.log('All of your products:', products)
As easy as that. Read our docs for more specifics.
🔥🔥🔥 Flame on!! 🔥🔥🔥