My Code is this but it doesnt work;
const functions = require('firebase-functions');
exports.randomNumber = functions.https.onRequest((request, response) => {
return Math.floor(Math.random() * 20)
});
My Code is this but it doesnt work;
const functions = require('firebase-functions');
exports.randomNumber = functions.https.onRequest((request, response) => {
return Math.floor(Math.random() * 20)
});
From https://firebase.google.com/docs/functions/http-events#terminate_http_functions ,
Always end an HTTP function with send(), redirect(), or end()
So your function will be:
const functions = require('firebase-functions');
exports.randomNumber = functions.https.onRequest((request, response) => {
response.send(Math.floor(Math.random() * 20))
});
Update: From this SO thread, you can't send only numbers in express.
Try this, it will make it string and send (credit to 1):
exports.randomNumber = functions.https.onRequest((request, response) => {
var randN = Math.floor(Math.random() * 20);
response.send(''+randN);
});