Skip to content

Instantly share code, notes, and snippets.

@NickFoden
Created September 13, 2020 20:21
Show Gist options
  • Save NickFoden/19a270d679fbf9fcf9def7c91c180fb9 to your computer and use it in GitHub Desktop.
Save NickFoden/19a270d679fbf9fcf9def7c91c180fb9 to your computer and use it in GitHub Desktop.
Firebase Functions
const functions = require("firebase-functions");
const express = require("express");
const admin = require("firebase-admin")
admin.initializeApp(functions.config().firebase)
// once you have the admin initialized then can access other parts of project
// say the real time database
const realTimeDB = admin.database();
const userRef = realTimeDB.ref("users").child("user_uid_or_such_here");
const app = express();
app.get("/", (req, res) => {
res.status(200).send({ data: "wordly hellos" });
});
exports.app = functions.https.onRequest(app);
// Chron jobs
//https://firebase.google.com/docs/functions/schedule-functions
// example at 12:01 am every first of the month NYC time
exports.chooseWhateverNameYouWant = functions.pubsub
.schedule("01 0 1 * *")
.timeZone("America/New_York")
.onRun((context) => {
// do the stuff
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment