0

I am wanting to save one simple string in firebase database from using firebase functions. I have this working and saving the string "THIS NEW CODE". What is simplest way to retrieve this string?

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

var ref = admin.database().ref("key").set("THIS NEW CODE");
Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
DevJZ
  • 100
  • 8

1 Answers1

0
admin.database().ref("key").once('value').then(snap => {
    const string = snap.val()
})

You should probably familiarize yourself with the documentation for the Admin SDK.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
  • im getting the same 2 errors as this post, https://stackoverflow.com/questions/48582278/eslint-error-trying-to-deploy-functions-firebase?rq=1 using solution in link i get error: Each then() should return a value or throw promise/always-return ive been trying to add a return null; to the answer above, it gets the 2 errors – DevJZ Jun 30 '18 at 02:26
  • You're going to have to learn asynchronous programming with JavaScript promises in order to be effective at writing Cloud Functions. – Doug Stevenson Jun 30 '18 at 02:28
  • ref.once("value", function(data) { // do some stuff once }); in the documentation link works, should be using the arrow function instead? – DevJZ Jun 30 '18 at 02:28
  • im new to javascript. ive been trying to follow a long with your videos, the typescript transition has slowed me with the videos. i appriciate the approach in your videos! – DevJZ Jun 30 '18 at 02:39