Last active
June 28, 2022 10:24
-
-
Save magician11/d16a0e3c0b3665258fa2f5c546f4056f to your computer and use it in GitHub Desktop.
Writing data to Firebase from Node.js
This file contains 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
Depreciated?