If you have no idea how to operate with firebase, or you don't wanna waste time writting basic operations in your project, this is your ideal package!
- Firebase credentials
- Node 16 or higher
npm i firebase-easy-functions
Create a "credentials.json" file in the root of the project and fill with your firebase credentials" Example:
{
"apiKey": "",
"authDomain": "",
"projectId": "",
"storageBucket": "",
"messagingSenderId": "",
"appId": ""
}
Single imports
const { createCollection } = require('firebase-easy-functions')
Or multiple imports
const { createCollection, deleteCollection } = require('firebase-easy-functions')
Or ES6
import { createCollection } from 'firebase-easy-functions'
import { createCollection, deleteCollection } from 'firebase-easy-functions'
createCollection(collectionName)
collectionName will be the name of the collection. The function will return successfull message.
deleteCollection(collectionName)
collectionName will be the name of the collection. The function will delete all the data in the collection and return true (bool)
createDocument(collectionName, documentId, object)
collectionName will be the name of the collection. documentId will be the "id" of your documment. object (optional) will be the data of your documment. The function will return the create firestore payload (_writtedocument, etc).
deleteDocument(collectionName, documentId)
collectionName will be the name of the collection. documentId will be the "id" of your documment. The function will return the delete firestore payload (_writtedocument, etc).
findById(collectionName, documentId)
collectionName will be the name of the collection, documentId will be the "id" of your documment. The function will return all the data of the document.
findAllDocuments(collectionName)
collectionName will be the name of the collection. The function will return all the documents in the collection.
collectionLength(collectionName)
collectionName will be the name of the collection. The function will return the length (in numbers) of the collection
getByPosition(collectionName, position)
collectionName will be the name of the collection, and position will be the specific position of a document you want The function will return the data that document.
findAllCollections()
The function will return a list of all the collections in your db