Skip to content

Instantly share code, notes, and snippets.

@elliotlarson
Last active April 21, 2021 13:44
Show Gist options
  • Save elliotlarson/8e16160c93d58f10646be006243441e7 to your computer and use it in GitHub Desktop.
Save elliotlarson/8e16160c93d58f10646be006243441e7 to your computer and use it in GitHub Desktop.
Simple Node.js Firebase repl
#!/usr/bin/env node
// Using the firebase-admin approach where database security rules do not apply.
// Here you are authenticating with a private key. The key JSON file is available via
// the Firebase web UI: project settings > service accounts > generate new private key.
var admin = require("firebase-admin");
admin.initializeApp({
credential: admin.credential.cert(".adminServiceAccountKey.json"),
databaseURL: "https://databaseName.firebaseio.com"
});
var database = admin.database();
var repl = require("repl");
var replServer = repl.start({
prompt: "firebase> ",
});
replServer.context.admin = admin;
replServer.context.database = database;
#!/usr/bin/env node
// Using the firebase approach where you are subject to database security rules.
var firebase = require('firebase')
var config = {
apiKey: "apiKey",
authDomain: "projectId.firebaseapp.com",
databaseURL: "https://databaseName.firebaseio.com",
storageBucket: "bucket.appspot.com"
}
firebase.initializeApp(config);
var database = firebase.database();
var repl = require("repl");
var replServer = repl.start({
prompt: "firebase> ",
});
replServer.context.firebase = firebase;
replServer.context.database = database;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment