-
-
Save jningtho/d8fc6ce085f0aa4e7a8719b982c30b06 to your computer and use it in GitHub Desktop.
Writing data to Firebase from Node.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const admin = require('firebase-admin'); | |
admin.initializeApp({ | |
credential: admin.credential.cert('./movies-387bf-firebase-adminsdk-4hoi8-c52699119b.json'), | |
databaseURL: 'https://movies-387bf.firebaseio.com', | |
}); | |
// Get a database reference to our blog | |
const db = admin.database(); | |
// creating a starting path in our database | |
const ref = db.ref('server/saving-data/fireblog'); | |
// create a child node of the above path and write the following data to it | |
const usersRef = ref.child('users'); | |
usersRef.set({ | |
alanisawesome: { | |
date_of_birth: 'June 23, 1912', | |
full_name: 'Alan Turing', | |
}, | |
gracehop: { | |
date_of_birth: 'December 9, 1906', | |
full_name: 'Grace Hopper', | |
}, | |
}); | |
// update the above data with nicknames | |
usersRef.update({ | |
'alanisawesome/nickname': 'Alan The Machine', | |
'gracehop/nickname': 'Amazing Grace', | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment