Server-side connecting and querying Firebase from Node.JS

less than 1 minute read

It took me a bit of work to figure out how to connect to and query Firebase from a (server-side, naturally) Node script, so, in order to make it easier in the future, here goes a rough draft of how you can do it:

const firebase = require('firebase');

const firebaseConfig = {
    apiKey: '<your-api-key>',
    authDomain: '<your-domain>',
    databaseURL: 'https://<your-domain>',
    storageBucket: '<your-domain>'


const db = firebase.database();

firebase.auth().signInWithEmailAndPassword('', 'YoUrPaSsWoRd').catch(error => {
    console.log('Error while authenticating:', error);
}).then(loginObject => {
    if (loginObject) {
        // now do your thing!
        let something = db.ref('users/' + loginObject.uid + '/something');
        // do something with something
    } else {
        console.log('Oops, something went wrong while authenticating:', loginObject);

That should be enough to get you started.

Leave a Comment