Importing / Adding the dependencies
First ensure that you load the flamelink
package to your file. When using the <script>
tag version, you will need to load both firebase
and flamelink
which will then be globally available on the browser's window
object.
Depending on your app setup, you can import the package using require()
statements:
var flamelink = require('flamelink')
or using ES2015/ES6/TypeScript imports:
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
You can create your flamelink
app instance by passing in a firebaseApp
instance along with any other flamelink
config options (remember to import firebase
of firebase-admin
first):
// Firebase app is always required and must be first
import firebase from 'firebase/app'
// Add additional services that you want to use
import 'firebase/auth'
import 'firebase/database'
import 'firebase/storage'
// import 'firebase/firestore'
// import 'firebase/messaging'
// import 'firebase/functions'
// Flamelink app is always required
import flamelink from 'flamelink/app'
// Add additional modules that you want to use
import 'flamelink/content'
import 'flamelink/storage'
// import 'flamelink/settings'
// import 'flamelink/navigation'
// import 'flamelink/users'
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,
env: 'production', // optional, defaults to `production`
locale: 'en-US', // optional, defaults to `en-US`
dbType: 'rtdb', // optional, defaults to `rtdb` - can be 'rtdb' or 'cf' (Realtime DB vs Cloud Firestore)
})
?> Tip: Go to your Firebase console to find the Firebase web config settings.
When using the firebase-admin
SDK in a Node.js server environment, the installation is similar (example imports everything, but you can also only require
what you need):
const admin = require('firebase-admin')
const flamelink = require('flamelink')
const serviceAccount = require('path/to/serviceAccountKey.json')
const firebaseConfig = {
credential: admin.credential.cert(serviceAccount), // required
databaseURL: '<your-database-url>', // required
storageBucket: '<your-storage-bucket-code>', // required if you want to use any Storage functionality
}
const firebaseApp = admin.initializeApp(config)
const app = flamelink({
firebaseApp,
dbType: 'cf',
})
You can use any of the different ways to create the admin firebaseApp instance, as long as you provide it to the flamelink function as firebaseApp
.
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 your firebase database. Suppose you want to retrieve all your products created under the "Content" section in flamelink
.
Using async-await:
try {
const products = await app.content.get({ schemaKey: 'products' })
console.log('All of your products:', products)
} catch (error) {
// handle any errors
}
Using standard Promises:
app.content.get({ schemaKey: 'products' })
.then(products => console.log('All of your products:', products))
.catch(error => // handle any errors)
!> Since Flamelink is built on top of Firebase, anything you can do with Firebase, you can do with Flamelink, eg. do you need a REST API, use the Firebase REST API directly.
Check out the API docs for all the available methods!