npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

firebase-express-sdk

v1.0.9

Published

A Firebase Firestore helper SDK for Express.js applications. Simplify interaction with Firebase Firestore by using this SDK to easily set up and manage CRUD operations for collections, handle API endpoints, and streamline data retrieval and manipulation i

Downloads

3

Readme

Firebase Express SDK

https://nodei.co/npm/firebase-express-sdk.png?downloads=true&downloadRank=true&stars=true

Simplify interaction with Firebase Firestore by using this SDK to easily set up and manage CRUD operations for collections, handle API endpoints, and streamline data retrieval and manipulation in your Express.js projects.

Uygulama Ekran Görüntüsü

Quick Start

Set up an Express server

mkdir firebase-express-tutorial
cd firebase-express-tutorial
npm init -y

Install the dependencies

npm install express cors body-parser
npm install -D nodemon

Install the Firebase Express SDK:

npm install firebase-express-sdk

Create a new file named index.js and add the following code:

const express = require("express");
const cors = require("cors");
const bodyParser = require("body-parser");
const { FirebaseExpressSdk } = require("firebase-express-sdk");

// We will be back to this later

Create a Firebase project

Go to the Firebase console and create a new project.

Add Cloud Firestore to your project.

For more details about setting up Cloud Firestore, check out the official documentation.

Generate a service account

Go to the service accounts page and generate a new private key.

Save the file in your project directory and name it serviceAccount.json.

The project directory should look like this:

.
├── node_modules
├── serviceAccount.json
├── index.js
├── package.json
└── package-lock.json

Initialize the Firebase Express SDK

Add the following code to the index.js file:

const express = require("express");
const cors = require("cors");
const bodyParser = require("body-parser");
const { FirebaseExpressSdk } = require("firebase-express-sdk");
const serviceAccountFile = require("./serviceAccount.json");

const app = express();
const port = 3001;

app.use(cors());
app.use(bodyParser.json());

const collections = {
  users: {
    documentAttributes: ["name", "age", "email"],
  },
};

const firebaseExpressSdk = new FirebaseExpressSdk({
  app, // Express app
  serviceAccountFile, // Firebase service account file
  collections, // Collections to expose,
  port, // Port to listen to (default: 3000)
});

firebaseExpressSdk.addActions([
  {
    collection: "users",
    endpoint: "/api/getUsers",
    request: {
      type: "GET",
    },
  },
  {
    collection: "users",
    endpoint: "/api/addUser",
    request: {
      type: "POST",
    },
  },
]);

Start the server

Add the following script to the package.json file:

"scripts": {
  "start": "nodemon index.js"
}

Start the server:

npm start

Test the endpoints and enjoy!

Make a GET request to http://localhost:3000/api/getUsers and you should get an empty array.

Make a POST request to http://localhost:3000/api/addUser with the following body:

{
  "name": "John Doe",
  "age": 25,
  "email": "[email protected]"
}

Make a GET request to http://localhost:3000/api/getUsers and you should get the following response:

{
  "status": "success",
  "data": [
    {
      "name": "John Doe",
      "age": 25,
      "email": "[email protected]"
    }
  ]
}

We encourage you to explore the Documents section for a deeper dive into the various features and functionalities of Firebase Express SDK.

Contributing

We value your contributions and look forward to working with you to enhance Firebase Express SDK.

To start contributing, take a look at Contributing guide