Thursday, 8 June 2017

how to store firebase snap.val() in a varible to use else where?

how would one go and store data from the firebase database using javascript. I want to use the once method so its not constantly looking up for any changes. For example like this:

database.child('readOnly/something').once('value').then((snap) => {
        const groupObj = [
            snap.val()
        ]
    });
    app.get('/something',(req,res)=>{
            res.render('something',{
                "groupList": groupObj
            });
        });
            // Individual Life Groups
            app.get('/something/:name',(req,res)=>{
                const group = req.path.split("/").pop();
                console.log(groupObj.length)
                for (i = 0; i < groupObj.length; i+=1) { 
                    if(groupObj[i].url   == group){
                        var desiredGroup = groupObj[i];
                        console.log(desiredGroup);
                        break;
                    }
                }
                res.render('group', desiredGroup);
                // To-Do: Add Data and Bindings
            });

I am using the up to date versions of expressjs, firebase, nodejs, and npm.



via Daniel Rustrum

No comments:

Post a Comment