Introducing Flame-Core 🔥: Simplifying Firebase Operations Like Express.js for Node.js

    4 min read
    681 words

    Working with Firebase can sometimes feel overwhelming, especially when dealing with boilerplate code and repetitive operations. To address these challenges, I’m excited to introduce Flame-Core, a new npm package designed to simplify Firebase operations just as Express.js simplifies Node.js operations.

    What is Flame-Core?

    Flame-Core is a TypeScript-based library that abstracts common Firebase functionalities, enabling developers to interact with Firebase more intuitively and efficiently. Whether you're working on Firestore, Realtime Database, Authentication, or other Firebase modules, Flame-Core minimizes the complexities, allowing you to focus on building features rather than wrestling with repetitive code.

    Why Use Flame-Core?

    1. Developer Productivity

    Flame-Core provides easy-to-use methods for common Firebase operations, reducing the need to write boilerplate code.

    2. TypeScript Support

    Built with TypeScript, Flame-Core ensures type safety and better developer experience with autocomplete features and compile-time error detection.

    3. Express.js-like Simplicity

    Much like how Express.js simplifies creating APIs, Flame-Core simplifies Firebase operations, making it accessible even for developers new to Firebase.

    4. Scalable and Flexible

    Designed with scalability in mind, Flame-Core is suitable for projects of all sizes, from small applications to enterprise-level solutions.

    Getting Started

    Installation

    To get started, install Flame-Core via npm:

    npm install flame-core
    

    Setting Up

    Import Flame-Core and initialize it with your Firebase configuration:

    import firebaseConfig from 'flame-core';
    
    firebaseConfig.initialize({
      apiKey: "your-api-key",
      authDomain: "your-auth-domain",
      projectId: "your-project-id",
      storageBucket: "your-storage-bucket",
      messagingSenderId: "your-messaging-sender-id",
      appId: "your-app-id",
    });
    

    Sample Code

    Authentication Made Simple

    Manage Firebase Authentication seamlessly:

    import { fireAuthService } from "flame-core";
    
    const authService = fireAuthService();
    
    // Sign up a new user
    await authService.register("test@example.com", "password123");
    
    // Log in a user
    await authService.login("test@example.com", "password123");
    
    // Log out the current user
     await authService.logout();
    
    //Signs in with Google using the specified method.
      //*Parameters: method: "popup" | "redirect" (default: "popup")
    await authService.signInWithGoogle();
    
    

    Firestore CRUD Operations

    Performing Firestore operations has never been easier:

    import { fireStoreDatabaseService } from "flame-core";
    
    const storageService = fireStoreDatabaseService();
    
    //Fetches all documents from a specified Firestore collection.
    const response = await storageService.getAll("users", {
      options: {
        where: {
          status: "completed",
          priority: { $gt: 1 },
          tags: { $arrCont: "important" },
          categories: { $arrContAny: ["work", "personal"] },
          type: { $in: ["task", "reminder"] },
          archived: { $ne: true },
        },
        populate: [
          ["departments", "department_id"],
          ["jobs", "job_id"],
          ["locations", "location_id"],
        ],
        sort: [
          ["createdAt", "desc"],
          ["priority", "asc"],
        ],
    
        startAfter: "cursorValue1",
        limit: 10,
      },
    });
    
    
    //Fetches a document by its ID.
    const response = await storageService.getById("users", {
      id: "12345",
    });
    
    //Creates a new document in a collection.
    const response = await storageService.create("users", {
      body: { name: "John Doe", age: 30, email: "user@mail.com" },
    });
    
    
    //Updates a document by its ID.
    const response = await storageService.updateById("users", {
      id: "12345",
      body: { age: 35 },
    });
    
    //Updates multiple documents by their IDs.
    const response = await storageService.updateBulk("users", ["12345", "67890"], {
      body: { status: "inactive" },
    });
    
    
    //Deletes a document by its ID.
    const response = await storageService.deleteById("users", {
      id: "12345",
    });
    
    //Deletes multiple documents by their IDs.
    const response = await storageService.deleteBulk(
      "users",
      ["12345", "67890"]
    );
    

    Use Cases

    • Rapid Prototyping: Quickly build applications without worrying about Firebase setup complexities.
    • Scalable Projects: Use Flame-Core’s organized structure for medium to large-scale applications.
    • Educational Projects: Simplify Firebase learning for beginners with intuitive methods.

    Community and Support

    We welcome contributions to make flame-core better! If you have ideas, or suggestions, or want to report issues, feel free to open a pull request or create an issue on GitHub. Let’s build something amazing together! 🚀

    GitHub repository🔥

    Support the Developer

    If you find this project helpful, consider buying me a coffee! Your support means the world. ☕ Buy Me A Coffee ⇗

    Conclusion

    Flame-Core is here to make Firebase operations a breeze. If you’ve ever felt bogged down by Firebase’s complexities, give Flame-Core a try and experience a more streamlined development process. Install it today, and simplify your Firebase journey!

    Check out Flame-Core🔥 on npm and start building smarter, not harder.


    Feel free to share your thoughts and feedback in the comments. Let’s build something amazing together! Happy coding! 😊