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?

2
  • What is your host operating system? Commented Apr 16, 2020 at 23:27
  • My host operating system is Windows 10 Commented Apr 16, 2020 at 23:33

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.