In the cmd terminal, I can run firebase projects:list to see the current project selected.
How can I get the current project when I run my nodejs script in the same terminal?
I have a list of projects to work on, first I use firebase use to pick a project to work on. Here is the result from firebase projects:list
┌──────────────────────┬──────────────────────┬────────────────┬──────────────────────┐
│ Project Display Name │ Project ID │ Project Number │ Resource Location ID │
├──────────────────────┼──────────────────────┼────────────────┼──────────────────────┤
│ Canvassing │ canvassing-xx │ xx │ us-west1 │
│ EC1 │ engage-xx │ xx │ us-central │
├──────────────────────┼──────────────────────┼────────────────┼──────────────────────┤
│ PVBC │ pvbc-xx (current) │ xx │ us-west1
In this case, the PVBC is the active project.
In my node project, I have a list of functions that need to push to firebase, something like
const functions = require('firebase-functions');
const admin = require('firebase-admin');
firestore = admin.firestore();
exports.updateState = functions.pubsub.schedule('every 1 minutes').onRun((context) => {
return bloc.updateActivityState(firestore);
});
I then use "firebase deploy" to push them to the current project I selected with firebase use.
I also have another set of functions that could do just manipulation from command line, like
var fc = require('../firebase_project1_name/config/firebaseConfig.js');
var firebaseConfig = fc.firebaseConfig;
var app = firebase.initializeApp(firebaseConfig);
var db = firebase.firestore(app);
var colDistrict = db.collection('districts');
...
I put firebase config in file and put them under folder of different project, I need a way to get the current project, like pvbc-xx and replace the firebase_project1_name with the proper name so I can get the config for the current selected project.
Even better, I am thinking if I can get current project info, I don't even need store firebase config in files, I may just get the info current firebase-admin.