Security News
pnpm 10.0.0 Blocks Lifecycle Scripts by Default
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
firebase-functions
Advanced tools
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.
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;
});
AWS Lambda is a serverless computing service provided by Amazon Web Services. It allows you to run code without provisioning or managing servers, similar to Firebase Functions. AWS Lambda supports a wide range of triggers, including HTTP requests via API Gateway, changes in DynamoDB, S3 events, and more.
Azure Functions is a serverless computing service provided by Microsoft Azure. It enables you to run event-driven code across various Azure services and third-party services. Azure Functions supports HTTP triggers, timer triggers, and triggers from other Azure services like Cosmos DB and Blob Storage.
Apache OpenWhisk is an open-source serverless platform that allows you to execute functions in response to events. It supports a variety of triggers, including HTTP requests, database changes, and message queues. OpenWhisk can be deployed on various cloud providers or on-premises.
The firebase-functions
package provides an SDK for defining Cloud Functions for Firebase.
Cloud Functions is a hosted, private, and scalable Node.js environment where you can run JavaScript code. The Firebase SDK for Cloud Functions integrates the Firebase platform by letting you write code that responds to events and invokes functionality exposed by other Firebase features.
Learn more about the Firebase SDK for Cloud Functions in the Firebase documentation or check out our samples.
Here are some resources to get help:
If the official documentation doesn't help, try asking through our official support channels: https://firebase.google.com/support/
Please avoid double posting across multiple channels!
// functions/index.js
const { onValueCreated } = require("firebase-functions/database");
const logger = require("firebase-functions/logger");
const notifyUsers = require("./notify-users");
exports.newPost = onValueCreated({ ref: "/posts/{postId}" }, (event) => {
logger.info("Received new post with ID:", event.params.postId);
return notifyUsers(event.data.val());
});
To contribute a change, check out the contributing guide.
© Google, 2017. Licensed under The MIT License.
FAQs
Firebase SDK for Cloud Functions
The npm package firebase-functions receives a total of 399,575 weekly downloads. As such, firebase-functions popularity was classified as popular.
We found that firebase-functions demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
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.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.