Skip to content

Instantly share code, notes, and snippets.

@magician11
Last active June 28, 2022 10:24
Show Gist options
  • Save magician11/d16a0e3c0b3665258fa2f5c546f4056f to your computer and use it in GitHub Desktop.
Save magician11/d16a0e3c0b3665258fa2f5c546f4056f to your computer and use it in GitHub Desktop.
Writing data to Firebase from Node.js
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',
});
@sfxworks
Copy link

sfxworks commented Apr 8, 2018

Depreciated?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment