0

My operating system is windows 10.
I have a scheduled firebase function that I would like to run locally:

functions = require('firebase-functions')
admin = require('firebase-admin')
exports.myFunction = functions.pubsub.schedule('every 30 minutes').onRun((context) => {
    console.log('Hello World!')
    return null
})

To run this function locally I run two commands(Answer taken from here):

firebase functions:shell
myFunction()

Can I execute this command in one line of code instead of two?

yuval
  • 2,848
  • 4
  • 31
  • 51

1 Answers1

0

Separate out the function logic from the scheduling logic, then call the function directly with node:

function.js:

const functions = require('firebase-functions')
const admin = require('firebase-admin')
const foo = require('./foo')
exports.myFunction = functions.pubsub.schedule('every 30 minutes').onRun(foo)

foo.js:

module.exports = (context) => {
  console.log('Hello World!')
  return null
}

Call with node in one line:

node -e 'require("./foo")()'

Note: You may need to manually supply the configuration/credentials in foo.js depending on what Firebase resources you are accessing since you are not running it in a Cloud environment when you call it directly.

Raine Revere
  • 30,985
  • 5
  • 40
  • 52