1

My index.js contains following code:

const functions = require('firebase-functions');  

const admin = require('firebase-admin');  
admin.initializeApp(functions.config().firebase);  

exports.addMessage = functions.https.onRequest((req, res) => {  

const original = req.query.text;  

admin.database().ref('/messages').push({original: original}).then(snapshot =>
{  
res.redirect(303, snapshot.ref);  
});  
});  

exports.makeUppercase = functions.database.ref('/messages/{pushId}/original').onWrite(event => {  
const original = event.data.val();  
console.log('Uppercasing', event.params.pushId, original);  
const uppercase = original.toUpperCase();  

return event.data.ref.parent.child('uppercase').set(uppercase);  
});  

I was using nodejs terminal to use Firebase. When I executed

>node index.js 

I got following error:

node_modules\firebase-functions\lib\config.js:51  throw new Error('Firebase config variables are not available.

Error: Firebase config variables are not available.  Please use the latest version of the Firebase CLI to deploy this function.  
    at init (D:\firebase\functions\node_modules\firebase-functions\lib\config.js:51:15)
    at Object.config (D:\firebase\functions\node_modules\firebase-functions\lib\config.js:29:9)  
    at Object.<anonymous> (D:\firebase\functions\index.js:6:31)  
    at Module._compile (module.js:570:32)  
    at Object.Module._extensions..js (module.js:579:10)  
    at Module.load (module.js:487:32)  
    at tryModuleLoad (module.js:446:12)  
    at Function.Module._load (module.js:438:3)  
    at Module.runMain (module.js:604:10)  
    at run (bootstrap_node.js:394:7)  
Abhinandan
  • 87
  • 1
  • 12
  • What is inside of `index.js`? – LEQADA Jul 18 '17 at 13:21
  • I have written two simple cloud functions to add value into firebase real-time database. But @LEQADA this is showing **config.js** related error, Isn't it? – Abhinandan Jul 18 '17 at 13:25
  • Could you update your question with content of `index.js` file? – LEQADA Jul 18 '17 at 13:26
  • And have you already tried this ['functions.config() is not available" with Cloud Functions for Firebase using Node.JS](https://stackoverflow.com/a/42978220/980828)? – LEQADA Jul 18 '17 at 13:27
  • Thanks @LEQADA for providing above link. That was so helpful. I got the reason why I got the error because I was trying to call the functions before deploy. – Abhinandan Jul 18 '17 at 13:50

0 Answers0