Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

firebase-functions

Package Overview
Dependencies
Maintainers
4
Versions
115
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

firebase-functions

Firebase SDK for Cloud Functions

  • 4.8.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
161K
decreased by-65.7%
Maintainers
4
Weekly downloads
 
Created

What is firebase-functions?

The firebase-functions npm package allows developers to create and deploy serverless functions that are triggered by Firebase and Google Cloud events. These functions can be used to handle HTTP requests, respond to changes in the Firebase Realtime Database or Firestore, authenticate users, and more.

What are firebase-functions's main functionalities?

HTTP Functions

HTTP functions allow you to create endpoints that can be triggered via HTTP requests. This is useful for creating RESTful APIs or handling webhooks.

const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();

exports.helloWorld = functions.https.onRequest((request, response) => {
  response.send('Hello from Firebase!');
});

Firestore Trigger

Firestore triggers allow you to execute functions in response to changes in Firestore documents. This can be used for tasks like sending notifications or updating other parts of your database.

const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();

exports.onUserCreate = functions.firestore.document('users/{userId}').onCreate((snap, context) => {
  const newValue = snap.data();
  console.log('New user created:', newValue);
  return null;
});

Authentication Trigger

Authentication triggers allow you to run functions in response to user authentication events, such as user creation or deletion. This is useful for tasks like sending welcome emails or cleaning up user data.

const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();

exports.sendWelcomeEmail = functions.auth.user().onCreate((user) => {
  const email = user.email;
  console.log('Sending welcome email to:', email);
  // Add email sending logic here
  return null;
});

Realtime Database Trigger

Realtime Database triggers allow you to execute functions in response to changes in the Firebase Realtime Database. This can be used for tasks like data validation or synchronization.

const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();

exports.onDataChange = functions.database.ref('/path/to/data').onWrite((change, context) => {
  const beforeData = change.before.val();
  const afterData = change.after.val();
  console.log('Data changed from', beforeData, 'to', afterData);
  return null;
});

Other packages similar to firebase-functions

Keywords

FAQs

Package last updated on 19 Mar 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc